Like Steve said, if you want to talk more about it, use:
https://groups.google.com/forum/?fromgroups=#!forum/rubyonrails-talk or
StackOverflow is very responsive (just tag it properly and ask answerable
questions).
But the two answers off the top of my head are using a module, and because
concerns are not just something used throughout Rails code and in gems, but
becoming a first-class citizen in Rails, read:
http://37signals.com/svn/posts/3372-put-chubby-models-on-a-diet-with-concerns
shared behavior in controllers could go into:
app/controllers/concerns
but you can just stick it anywhere in the path corresponding to the
concern''s namespace and it would get autoloaded.
or as of this past weekend you could use the permitters gem:
https://github.com/permitters/permitters
but for vanilla Strong Parameters, module include is good way, and a
concern may as well be the right way (depending on whether you are ok with
the minor overhead in not using Ruby directly).
Mostly just using this as an excuse to post links, like usual. Will lay off
now...
On Thursday, May 2, 2013 3:13:48 PM UTC-4, prin...@gmail.com
wrote:>
> Hi there!
>
> I''ve got code duplication using strong_parameters:
>
> class PeopleController < ApplicationController
> # ...
>
> protected
> def person_params
> params.permit(:name, pets: [ :name, :age ])
> end
> end
>
> ###
>
> class PetsController < ApplicationController
> # ...
>
> protected
> def pets_params
> params.permit(:name, :age)
> end
> end
>
> So if I need change permitted params for pets I should change it in two
> files.
> Am I doing wrong? Or how can I avoid code repetition?
>
> Thanks in advance!
>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to rubyonrails-core+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.