Reputation: 33348
I'm getting this error:
/Applications/MAMP/htdocs/clippo2/app/controllers/projects_controller.rb:31: syntax error, unexpected ',', expecting => ...:user_id => [1], :instructions, :max_duration, :active, :max... ... ^
From this method while trying to implement the Rails 4 strong parameters:
private
def project_params
params.require(:project).permit(:user_id => [1], :instructions, :max_duration, :active, :max_videos, :hashed_id)
end
What am I doing wrong?
Upvotes: 2
Views: 1213
Reputation: 54882
Try to remove the "=> [1]
" after the :user_id
symbol:
params.require(:project).permit(:user_id => [1], :instructions, :etc) ^^^^^^^
params.require(:project).permit(:user_id, :instructions, :etc)
Or if you want to keep it, use { }
:
params.require(:project).permit({:user_id => [1]}, :instructions, :etc)
Or use ruby syntax parser to your advantage (see more info below):
params.require(:project).permit(:instructions, :etc, :user_id => [1])
This is actually a ruby feature. The latest arg given to a method is implicitly a Hash, therefore you don't need the curly braces {
and }
on the latest arg object.
For example, calling a method like this:
permit(1,2,3, :some => :var, :of => :a, :ruby => :hash)
Is the exact same thing as doing:
permit(1,2,3, { :some => :var, :of => :a, :ruby => :hash })
But passing the args in a different order would break the parser if the hash is first without the curly braces {
and }
.
Upvotes: 4