Reputation: 707
I have a table called 'Wbs'. I've generate the controller which works fine when executing from the command line.
Example:
Wbs
Wbs(id: integer, description: string, project_id: integer, wbs_no: string, published: boolean, created_at: datetime, updated_at: datetime))
The problem is when I attempt to return all Wbs objects for a given project. Rails removes the 's' from wbs and tries to make a call to a method called "Project::Wb" instead of "Project::Wbs".
Example:
Projects.first.wbs
Project Load (0.4ms) SELECT "projects".* FROM "projects" LIMIT 1 NameError: uninitialized constant Project::Wb
I do have belong_to and has_many set in their respective models.
How can I fix this issue?
Upvotes: 0
Views: 55
Reputation: 114188
You can specify that "wbs" is uncountable. In config/initalizers/inflections.rb
add:
ActiveSupport::Inflector.inflections do |inflect|
inflect.uncountable "wbs"
end
You'll have to restart your server / console afterwards.
Upvotes: 0
Reputation: 1452
I think, you should tell the Rails that your model name is not like it is expecting for. You could do so with:
has_many :wbs, :class_name => "Wbs"
Upvotes: 0