RailsCasts Pro episodes are now free!
Learn more or hide this
GitHub User: purban
If you use this with more than 1 model here is an example of how you could refactor your PermittedParams class to allow more flexibility:
class PermittedParams < Struct.new(:params, :user) %w(topic user).each do |m| define_method(m) { params.require(m.to_sym).permit(*send("#{m}_attributes".to_sym)) } end def topic_attributes if user && user.admin? [:name, :sticky] else [:name] end end def user_attributes [:email, :password, :password_confirmation] end end
If you use this with more than 1 model here is an example of how you could refactor your PermittedParams class to allow more flexibility: