2012-08-13 56 views
15

我有一个型号为ActiveDns。当我运行导轨 - 型号名称以S结尾

rails g scaffold_controller ActiveDns 

我得到的消息检测模型的

复数形式,采用单一化的版本。用--force-plural覆盖。现在

,控制器和视图生成假装单数ActiveDn和复数是ActiveDns,我也得到愚蠢的东西一样link_to new_dn_path。该--force-plural说法似乎并没有解决这个问题:

rails g scaffold_controller ActiveDns --force-plural 

仍然导致使用命名@active_dn变量视图中使用new_dn_path控制器,护栏3.2.3。我正在尝试使用rails d scaffold_controller ActiveDns删除文件。

什么是正确的方法来做到这一点?

+2

而是手动删除不正确的文件,也可以只'轨破坏scaffold_controller ActiveDns' – 2012-08-13 06:16:28

回答

14

什么是正确的方法来做到这一点?

我使用inflectionsdocument不可数的实体。

配置/初始化/是inflections.rb

ActiveSupport::Inflector.inflections do |inflect| 
    inflect.uncountable "ActiveDns" 
end 

然后你得到:

$ rails g scaffold_controller ActiveDns 
     create app/controllers/active_dns_controller.rb 
     invoke erb 
     create app/views/active_dns 
     create app/views/active_dns/index.html.erb 
     create app/views/active_dns/edit.html.erb 
     create app/views/active_dns/show.html.erb 
     create app/views/active_dns/new.html.erb 
     create app/views/active_dns/_form.html.erb 
     invoke test_unit 
     create test/functional/active_dns_controller_test.rb 
     invoke helper 
     create app/helpers/active_dns_helper.rb 
     invoke test_unit 
     create  test/unit/helpers/active_dns_helper_test.rb 

这是你想要的吗?

11

我与测试轨道-3.2(我猜应该使用Rails-3.x的工作)

打开config/initializers/inflections.rb,增加一条规则:

ActiveSupport::Inflector.inflections do |inflect| 
    inflect.irregular 'dns', 'dnses' 
end 

,并生成控制器

rails g scaffold_controller ActiveDns 

并添加路由到您的config/routes.rb文件

resources :active_dnses 

那么你应该看到:

$ rake routes 

    active_dnses GET /active_dnses(.:format)   active_dnses#index 
       POST /active_dnses(.:format)   active_dnses#create 
new_active_dns GET /active_dnses/new(.:format)  active_dnses#new 
edit_active_dns GET /active_dnses/:id/edit(.:format) active_dnses#edit 
    active_dns GET /active_dnses/:id(.:format)  active_dnses#show 
       PUT /active_dnses/:id(.:format)  active_dnses#update 
       DELETE /active_dnses/:id(.:format)  active_dnses#destroy 
+0

对我来说工作正常轨道4.2.1 – 2015-06-26 18:19:26