Home how to solve a TypeError error in rails 4 in the form?
Reply: 1

how to solve a TypeError error in rails 4 in the form?

vidur punj
vidur punj Published in 2017-11-14 08:03:02Z

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| %>
<%= vehical.label 'house power'%>
  <%= vehical.text_field 'horse_power'%>
      <%= vehical.label 'brand' %>
      <%= vehical.text_field 'brand' %>
      <%= vehical.label 'model' %>
      <%= vehical.text_field 'model' %>

    <%= vehical.submit 'create' %>
<% end %>

routes for it:

 match '/vehicals/create', :to => 'vehicals#create', :as => 'vehicals_create', :via => :post


ActionView::Template::Error (no implicit conversion of Symbol into Integer):
    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

NM Pennypacker
NM Pennypacker Reply to 2017-11-14 16:26:12Z

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
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.328165 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO