user1340906
user1340906

Reputation: 11

NameError: uninitialized constant when calling form_for

-My routes.rb

-resources :manufacturers do - resources :vehicle_data -end

-In controller

-In Views

-<%= form_for([@manufacturer, @manufacturer.vehicle_data.build]) do |f| %>

-When trying to create new record

-NameError in Vehicle_data#index

-Showing C:/Users.../app/views/vehicle_data/index.html.erb where line #12 raised:

-uninitialized constant Manufacturer::VehicleDatum -Extracted source (around line #12):

-9: -10: -11: -12: <%= form_for([@manufacturer, @manufacturer.vehicle_data.build]) do |f| %> -13:
-14:

How do I make this form work??? Why the model name is changed from VehicleData to VehicleDatum

Upvotes: 0

Views: 2024

Answers (1)

Ben Taitelbaum
Ben Taitelbaum

Reputation: 7403

Rails expects models to be the singular form of the resource you defined, and the singular of data is datum, so it expects your class to be a VehicleDatum. If this isn't the pluralization that you want to use, see How do I override rails naming conventions?

Upvotes: 3

Related Questions