Where to put a piece of code in Ruby on Rails?

Posted by yuval on Stack Overflow See other posts from Stack Overflow or by yuval
Published on 2010-06-02T05:19:22Z Indexed on 2010/06/02 5:23 UTC
Read the original article Hit count: 199

I have a post controller that has many comments. The post model has a field called has_comments which is a boolean (so I can quickly select from the database only posts that have comments). To create a new comment for a post, I use the create action of my comments controller.

After I create the comment I need to update my post's has_comments field and set it to true.

I can update this field from the create action of my comments controller, but that doesn't seem right - I feel that I should really be using the post's update action, but I'm not sure if it's right to call it (via send?) from the create action of the comments controller.

Where should the code for updating the post be? Thank you!

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about best-practices