0

-My routes.rb

-resources :manufacturers do - resources :vehicle_data -end

-In controller

  • def create
  • @manufacturer = Manufacturer.find(params[:manufacturer_id])
  • @vehicle_data = @manufacturer.vehicle_data.create(params[:vehicle_data])
  • @vehicle_data.save -end

-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

1 Answers1

3

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?

Community
  • 1
  • 1
Ben Taitelbaum
  • 7,343
  • 3
  • 25
  • 45
  • Inflector.inflections do |inflect| inflect.irregular 'VehicleDatum', 'vehicles' end +Getting error NameError: uninitialized constant Inflector – user1340906 Apr 25 '12 at 03:00
  • try putting it in config/initializers/inflectors.rb and use `ActiveSupport::Inflector` as in http://api.rubyonrails.org/classes/ActiveSupport/Inflector/Inflections.html – Ben Taitelbaum Apr 25 '12 at 03:13