I have a form to create vehicals and define the route corresponding to it, But it consistently gives a TypeError error, I think I am doing it wrong, please correct following is the code:
<%= form_for @vehical, url_for(:action => :create, :controller => 'vehicals') do |vehical| %>
<div>
<%= vehical.label 'house power'%>
<%= vehical.text_field 'horse_power'%>
</div>
<div>
<%= vehical.label 'brand' %>
<%= vehical.text_field 'brand' %>
</div>
<div>
<%= vehical.label 'model' %>
<%= vehical.text_field 'model' %>
</div>
<%= vehical.submit 'create' %>
<% end %>
routes for it:
match '/vehicals/create', :to => 'vehicals#create', :as => 'vehicals_create', :via => :post
Error:
ActionView::Template::Error (no implicit conversion of Symbol into Integer):
1:
2: <%= form_for @vehical, url_for(:action => :create, :controller => 'vehicals') do |vehical| %>
3: <div>
4: <%= vehical.label 'house power'%>
5: <%= vehical.text_field 'horse_power'%>
thanks in advance
You're passing a symbol for the action value. You need a string:
url_for(action: 'create', controller: 'vehicals')
You could also do this, but you may have to tweak the route helper if you don't have that route set up:
form_for @vehical, create_vehicle_path, method: :post
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments