Reputation: 10225
I am trying to upgrade my app from Rails 3 to Rails 4 and I can't seem to get the syntax right in line 12:
class ProjectsController < ApplicationController
before_filter :find_project
...
private
def find_project
@project = Project.find(params[:id])
end
def valid_people
if params[:project][:person_ids].present? # how to do this with strong parameters?
person_ids = params[:project][:person_ids].map(&:to_i)
valid_ids = current_user.people.pluck(:id)
redirect_to root_path if (person_ids - valid_ids).any?
end
end
def project_params
params.require(:project).permit(:name, :description, :person_ids)
end
end
I keep getting this error: Unpermitted parameters: person_ids
How can I use only the person_ids
parameter?
Thanks for any help.
Upvotes: 0
Views: 229
Reputation: 4956
The idea of strong parameters is that you call the function you have defined to get your parameters
if params[:project][:person_ids].present? # how to do this with strong parameters?
would become
if project_params[:person_ids].present? # how to do this with strong parameters?
also i'm guessing :person_ids
is an array if so replace your :person_ids
with {:person_ids => []}
Upvotes: 1