Forum: Ruby on Rails Activerecord Update syntax.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
4813ef5f30d01e02204dd3fe6a2cb48a?d=identicon&s=25 eddy (Guest)
on 2006-06-08 04: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!
4813ef5f30d01e02204dd3fe6a2cb48a?d=identicon&s=25 eddy (Guest)
on 2006-06-08 17:48
Anyone have an ideas?
D0cd6b10e01bacb976b3b815a9c660bc?d=identicon&s=25 Alex Wayne (Guest)
on 2006-06-08 19: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.
  topic.update_attributes(params[:topic])
This topic is locked and can not be replied to.