Reputation: 4091
This is my controller:
def addcar
@car = Car.new(params[:car])
render :action => "list"
end
this is my view:
<%(@allcars).each do |cell|%>
<p><%= link_to cell.to_s, :controller => "car", :action => "addcar", :car => cell.to_s %></p>
<%end %>
In the link_to
statement I want to pass cell.to_s
to the controller. How can I do that please? The cell.to_s
is just a string but I want it to be the name of the car object (car.Name
)
Upvotes: 1
Views: 4408
Reputation: 54782
Car.new(params[:car])
expects params[:car]
to be a Hash ({:foo => "bar"}
). So change your code:
<% @allcars.each do |cell| %>
<p>
<%= link_to cell.to_s,
:controller => "car",
:action => "addcar",
:car => { :name => cell.to_s } %>
</p>
<% end %>
Upvotes: 1