This what I have - sadly, it does not work :( . posts = {params[:topic][:forum_id] => { "posts_count" => "posts_count + @topic.posts_count"}, @topic.forum_id => { "posts_count" => "posts_count - @topic.posts_count" } } Forum.update(posts.keys, posts.values) It''s suppose to subtract the posts_count from topic, and add it and subtract it from posts_count from each board, respectively. I am fairly sure that "posts_count - @topic.posts_count" is what''s stopping it from working and was wondering how would i go about this better? Or if anyone can suggest an entirely better way to do this transaction that would also be appreciated. Thanks in advance! -- Posted via http://www.ruby-forum.com/.
Anyone have an ideas? -- Posted via http://www.ruby-forum.com/.
eddy wrote:> Anyone have an ideas?First of all, your setting the values in the hash to a string. No actual caclulations will happen here. You probably want something more like this that uses update_attributes which accepts a hash of values. topic = Topic.find(params[:id]) topic.post_count = #some calulation here. topic.update_attributes(params[:topic]) -- Posted via http://www.ruby-forum.com/.
Maybe Matching Threads
- Counter Problem
- Tag Cloud Code
- How do you detect if ActiveRecord ''update'' fails?
- Why does ActiveRecord allow perception of success when updating an ID, however it doesn't really work(i.e. no change in database)?
- ActiveRecord, << or push_with_attributes: update if exists?