Question

I cannot access the controller params hash as I expect. I understand it is a HashWithIndifferentAccess but no matter what I've tried I always run into this error wrong number of arguments (1 for 0)

Here is controller method:

def cuisine
   @selection = params("name")  // or params(:name)
end

Here is routes.rb

get '/cuisine/:name', to: 'main#cuisine'

What I get in the view from params itself (@selection) is a hash..

{"controller"=>"main", "action"=>"cuisine", "name"=>"american"}


I appreciate your help!

Was it helpful?

Solution

Write as

 @selection = params["name"] # or @selection = params[:name]

params("name") is params method call with one argument, not a Hash#[] method call. You need to use Hash#[].

OTHER TIPS

You should use square brackets:

def cuisine
   @selection = params["name"]  # or params[:name]
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top