On Oct 26, 12:51 pm, 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.

Huh? It's rails convention. A restful controller has 6 actions (index,
show, create, edit, update, destroy).

>
> > And as others have said, don't overwrite
>
> over*ride*

Wow, why so pedantic? The intent was clear. Did I kick your puppy or
something?

> > AR class methods like
> > 'create', otherwise you will enter a world of pain.
>
> 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.

That's a really bad example as the additional parameter is handled via
an association. Besides, if an attribute is not in the request
attributes hash, it's much easier to just add it in the controller,
since that's what you're already doing in a backwards sort of way.
Ex:  Foo.create(params[:foo].merge(:my_var => 'bar')) vs.  Foo.create
(params[:foo], 'bar') + an ugly overridden method in the class

-- W

> > 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!
>
>
>
> > -- 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to