I have a multiple select box for the has_many association. The parameters are:
foo_ids: ["1", "2", "3"]
Using strong parameters, I do not allow this attribute, because I would like to authorize it myself, so that people canβt just put what they need in them.
def update bar.foos = authorized_foos bar.update(baz_params) respond_with bar end private def authorized_foos foos = Foo.find(params[:baz][:foo_ids]) foos.each do |foo| authorize foo, :manage? end end
This approach will make me find all foos, skip them and allow each one separately. Is there an easier way to manage has_many authorization, preferably with a Pundit stone?
ruby-on-rails ruby-on-rails-4 strong-parameters pundit
Logan serman
source share