2011-06-09 61 views
4

我遇到了爲賽船會生成腳手架的問題。當我運行Rails 3拐點問題

rails g scaffold Regatta name:string start_date:datetime 

我得到一個型號命名regattum和控制器稱爲regatta_controller(而不是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 

相同的公共/樣式表/ scaffold.css

顯然這是一個拐點問題,但每當我修改/config/initializers/inflections.rb我得到一個錯誤說:

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. 

我已經嘗試了所有我能想到的工作,但我不斷收到錯誤。任何有關解決方案或解決方法的建議都將不勝感激!


更新

這裏有一些我已經試過的東西:

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

,所以我嘗試了一些下面的選項,其中包括這並沒有改變什麼,在不同組合中無效:

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

更新2

下面是我是inflections.rb使用一次我想出的代碼我在做什麼錯:

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

希望這將幫助別人的未來!

+0

你如何修改文件? – 2011-06-09 22:38:57

回答

1

鑑於錯誤消息說Regatta已經在您的應用程序中使用(顯然不是由Rails保留),我猜Regattum模型仍然存在。

我建議銷燬腳手架並再試一次。聽起來好像,一旦在應用程序中定義了一個單詞,Rails就有了一個內置的保護來防止改變變形。所以,拋出這個錯誤是爲了防止在這種情況下的意外行爲。

+0

我摧毀了腳手架 - 所以沒有模型,控制器或視圖 - 仍然沒有運氣與偏折器。我也從來沒有'rake db:migrate',所以也沒有數據庫表。我把頭髮拉過來。 – akpb 2011-06-09 23:14:55

+5

你說得對。我打電話給我的應用程序賽,這顯然是拋棄它。感謝您指點我正確的方向! – akpb 2011-06-09 23:40:18

9

我認識到這篇文章已經過時了,但我還是認爲我會貢獻我的發現。

經過很長時間的發展,我一直在將rpsec和黃瓜整合到我的應用程序中(是的;淘氣的,淘氣的)。我想爲我的模型生成rspec存根,並測試我的應用程序單元。我通常可以將關聯的遷移移出db/migrate /並運行'bundle exec rails g'來重新生成腳手架,在本例中爲rspec存根。這次不行。

<終端>

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. 

我的問題是在我的「配置/航線暫時註釋掉 'devise_for' 行解決。RB」文件

的config/routes.rb中

#devise_for :users 

賓果。這並不是唯一一次讓Devise讓我感到吃驚的「黑魔法」,這一點並不明顯。當然,一旦我的rspec存根被生成,我就不會評論該行。現在開始寫單元測試了!

+0

爲我工作!謝謝。 – Zeeshan 2013-12-22 22:51:15

+0

兩年多後,仍然相關。這也幫助了我,謝謝。 – Steve 2014-11-29 06:05:06