Ruby on Rails Error

I use Ruby on Rails to create a website for the game I play.

I have a User model and a Starbase model. The connection I'm trying to set up looks like this:

 class User < ActiveRecord::Base has_many :starbases end class Starbase < ActiveRecord::Base belongs_to :user end 

However, when I open the script / console and try to access the older categories of users, this gives me an error: NameError: uninitialized constant User::Starbasis .

This seems to be a kink problem and the rails are not pluralizing sprockets.

I tried adding this to the inflections.rb file in the intializers folder:

 ActiveSupport::Inflector.inflections do |inflect| inflect.plural 'starbase', 'starbases' end 

but he still does not solve the problem. Can anyone give some advice on how to do this?

Greetings

Eef

+4
source share
2 answers

You tried to add a line for backward inflection (ie, "singular"):

  inflect.singular "starbases", "starbase" 

I tried your example in my console, and it was the singularity that caused the problems, and not vice versa. I'm not sure if this fixes other problems (e.g. routes), but it should fix simple stuff (I think).

+5
source

A small trick that I chose to test how Active Support can produce a singularity, or to pluralize my class names and / or module names.

your rails application server is running, and on a new tab, enter the rails console by typing rails console . There you can easily check the correct style for your names.

long way ActiveSupport::Inflector.pluralize "fish" # => "fish"

shortcut "fish".pluralize # => "fish"

You can find more examples here.

https://github.com/rails/rails/blob/master/activesupport/test/inflector_test_cases.rb

0
source

Source: https://habr.com/ru/post/1335436/


All Articles