reusability of strong_parameters

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

Please post these kinds of questions to rubyonrails-talk, this list is for discussions about the framework itself, not how to use it.

Like Steve said, if you want to talk more about it, use: Redirecting to Google Groups 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:

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…