On Oct 26, 9:51 am, Marnen Laibow-Koser <rails-mailing-l...@andreas- s.net> wrote: > Wes wrote: > > Try this: > > > class ObjectivesController < ApplicationController > > before_filter :require_user > > layout false > > def create > > objective = current_user.objectives.create(params[:objective]) > > end > > end > > No! Create shouldn't be a controller method.
Why not? > > > > And as others have said, don't overwrite > > over*ride* > > > AR class methods like > > 'create', otherwise you will enter a world of pain. Thanks for the good practice tip. > Yeah. If you must override, it's probably best to do something like > > def create(attributes, user_id) > super(attributes.merge :user_id => user_id) > end > > but even this is kind of bad. > > > > > Also, you are deleting a param called 'freq_options', if the model > > does not need it then it shouldn't be in the hash. If the controller > > needs it, then pass it as params[:freq_options] rather than params > > [:objective][:freq_options]. If it's not used there, then why pass it > > at all? > > Good catch! > It will eventually be used, just not yet. > > > -- W > > Best, > -- > Marnen Laibow-Koserhttp://www.marnen.org > [email protected] > -- > Posted viahttp://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

