0

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?

2 Answers 2

0

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"
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.