Simon
Simon

Reputation: 13

Getting a Ruby "wrong number of parameters" on my params when creating a new record

I've looked at the other reported "wrong number of parameters" reports and tried the suggestions but to no avail. Any help would be greatly appreciated.

I'm getting the error "wrong number of arguments (3 for 1)" on this line:

  params.require(:bartroute_id, bartstation_id,:bart_route_station_sequence).permit(:bartroute_id, 
  :bartstation_id,:bart_route_station_sequence)

Here's the controller logic:

# Create a new route station association
def create
    binding.pry
    @bartroutestation = Bartroutestation.new(bartroutestation_params)
    if @bartroutestation.save
        flash[:success] = "Route station created"
        redirect_to bartroutes_path 
    else
        flash[:error] = "Unable to save route station. Please try again"
        render :create
    end
end

private
def bartroutestation_params
  params.require(:bartroute_id, :bartstation_id,:bart_route_station_sequence).permit(:bartroute_id,
  :bartstation_id,:bart_route_station_sequence)
end

end

and here's what's in the params:

=> {"utf8"=>"✓",
 "authenticity_token"=>"PToySCDEDfspMcG20//iwk+c+CqXOr5U3PkGFKujpYo=",
 "bartroute_id"=>"1",
 "bartstation_id"=>"1",
 "bart_route_station_sequence"=>"1",
 "button"=>"",
 "action"=>"create",
 "controller"=>"bartroutestations"}

I have other working controllers that follow the same pattern and they are working with no issues in the params and I don't see what's different with this one.

Thanks in advance for any help you can give a newbie.

Upvotes: 0

Views: 68

Answers (1)

usha
usha

Reputation: 29369

Since your parameters are not nested, it should just be

def bartroutestation_params
  params.permit(:bartroute_id,:bartstation_id,:bart_route_station_sequence)
end

Some documentation here

Upvotes: 2

Related Questions