Search code examples
ruby-on-rails-3before-filter

Pass object to before_filter to perform additional logic before create


I need perform some extra logic on an object before it is saved to the database. I would assume that using a before_filter would be the correct way to accomplish this, but I'm not sure how to pass the object to be saved into my before_filter method.


Solution

  • That all sounds like model code to me. To get the most out of Rails (or any MVC framework) follow the 'Fat Models, Skinny Controllers' rule of thumb. It can be taken too far, but I think in this case it's pretty clear. If there are errors with the helper functions you mention, shouldn't the save action fail with appropriate error messages?

    There's lots of good posts on SO on this subject. Here's one

    If this doesn't give you enough to work with I'd suggest posting some code.