The problem with rails 3

I have a problem generating a scaffold for a regatta. When i started

rails g scaffold Regatta name:string start_date:datetime 

I get a model called regattum and a controller called regatta_controller (instead of regattas_controller)

  invoke active_record create db/migrate/20110609221608_create_regatta.rb create app/models/regattum.rb invoke test_unit create test/unit/regattum_test.rb create test/fixtures/regatta.yml route resources :regatta invoke scaffold_controller create app/controllers/regatta_controller.rb invoke erb create app/views/regatta create app/views/regatta/index.html.erb create app/views/regatta/edit.html.erb create app/views/regatta/show.html.erb create app/views/regatta/new.html.erb create app/views/regatta/_form.html.erb invoke test_unit create test/functional/regatta_controller_test.rb invoke helper create app/helpers/regatta_helper.rb invoke test_unit create test/unit/helpers/regatta_helper_test.rb invoke stylesheets 

identical to public / stylesheets / scaffold.css

Obviously this is a kink problem, but whenever I change /config/initializers/inflections.rb, I get an error:

 The name 'Regatta' is either already used in your application or reserved by Ruby on Rails. Please choose an alternative and run this generator again. 

I tried everything I could think of to make it work, but I get an error all the time. Any advice on a solution or workaround would be greatly appreciated!


Update

Here are some of the things I've tried:

 ActiveSupport::Inflector.inflections do |inflect| inflect.irregular 'regatta', 'regattas' end 

This did not change anything, so I tried several options below, among others, in different combinations to no avail:

  inflect.plural 'regatta', 'regattas' inflect.singular 'regattas', 'regatta' inflect.singular 'regatta', 'regatta' 

Update 2

Here is the code I used in inflections.rb when I realized what I was doing wrong:

 ActiveSupport::Inflector.inflections do |inflect| inflect.plural 'regatta', 'regattas' inflect.singular 'regatta', 'regatta' inflect.singular 'regattas', 'regatta' end 

Hope this helps someone in the future!

+4
source share
2 answers

Given the error message that Regatta already used in your application (it is not explicitly reserved by Rails), I assume that the Regattum model is still in place.

I would recommend destroying the scaffold and retrying. It seems that as soon as the word is already defined in the application, Rails has built-in protection against kink changes. Thus, this error occurs to protect against unexpected behavior in this very situation.

+1
source

I admit that this post is outdated, but I thought I contributed as well.

I integrated rpsec and cucumber into my application after a lot of development (yes, naughty, naughty). I wanted to generate sts rspec for my models and get testing of my application. Usually I can move the associated migration from db / migrate / and run "bundle exec rails g" to regenerate the forests, in which case rspec stubs. Not this time.

<terminal>

 bundle exec rails g scaffold User email:string ... updated_at:datetime roles_mask:integer --trace invoke active_record The name 'User' is either already used in your application or reserved by Ruby on Rails. Please choose an alternative and run this generator again. 

My problem was resolved by temporarily commenting out the line 'devise_for' in the file 'config / routes.rb'

config / routes.rb

 #devise_for :users 

Bingo. And this is not the only time that Devise surprised me with "black magic", which is not always obvious. I did not comment on this line as soon as my rspec stubs were created. Now let's start writing unit tests!

+9
source

All Articles