Is the name already in use or reserved by Ruby on Rails?

I created the rails application with the following command:

rails new Education 

Now I am trying to create a new model in rails with the following command:

 rails generate model Education name:string 

When starting, it produces the following error:

The name "Education" is either already used in your application or is Reserved by Ruby on Rails. Please select an alternative and start the generator again.

Since I just created a new application and I only have one other model, is it hard for me to think of any reason why Rails would reserve such a name?

Any thoughts on where this error came from and how can I get around it?

(I tried to change the name to another, and it works as expected. Since the name really matches its purpose, I do not want to change its name if there is no other way!)

I am using Ruby 2.0.0 with Rails 4.0.0 and PostgreSQL

+11
ruby ruby-on-rails ruby-on-rails-4
source share
1 answer

You cannot create a model with the same name as the application, because it will create conflicting names. When you create an application, i.e. rails new Education , he will create a module called Education as follows

 module Education class Application < Rails::Application #.... end end 

This named module is called in files such as config.ru , routes.rb and environment.rb and many others. Therefore, if you could create a model class with the same name, this would create ambiguity as to whether you are invoking a model or module.

+30
source share

All Articles