I'm using form for and the name of the form in the controller is appearing as "#", but I expect it to appear as :edge.
Here's my controller:
def new
#some_stuff
@edge = Edge.new
#some_stuff
end
def create
@edge = Edge.new(edge_params)
@edge.save
end
def edge_params
params.require(:edge).permit(:location_1_id, :location_2_id)
end
View:
<%= form_for( :edge, :url => {:action => 'create'}) do |f| %>
<ul>
<li>
<%= f.label :location_1_id %>
<%= collection_select(@edge, :location_1_id, @location, :id, :record_as_string) %>
</li>
<%= submit_tag(t(:create_edge)) %>
</ul>
<% end %>
Param req:
{"utf8"=>"✓", "authenticity_token"=>"blah", "#"=>{"location_1_id"=>"91", "location_2_id"=>"92"}, "commit"=>"Create Edge", "action"=>"create", "controller"=>"admin/edges", "floor_map_floor_id"=>"1"}
So the name of the parameter should be :edge but it's an object that I can't access.
Can anybody tell me what I'm missing? Any help is appreciated.
You should be using the form block on your collection set like so
(notice that you are calling the collection_select on the block variable
f
, and NOT passing in the @edge as the first argument).In addition, because you are creating the object in new (
@edge = Edge.new
), you should just be using in your form, like so(although using
:edge
wasn't the cause of your problems, I suspect it was because you were using:edge
and@edge
in the same form. You need to be consistent, use one or the other)