Forum: Ruby on Rails Activerecord Update syntax.

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
eddy (Guest)
on 2006-06-08 06:40
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!
eddy (Guest)
on 2006-06-08 19:48
Anyone have an ideas?
Alex W. (Guest)
on 2006-06-08 21:50
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.
This topic is locked and can not be replied to.