ruby-on-rails – Rails – 型号以S结尾

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – Rails – 型号以S结尾前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个名为ActiveDns的模型.当我跑
rails g scaffold_controller ActiveDns

我收到消息

Plural version of the model detected,using singularized version. Override with –force-plural.

现在,控制器和视图被假定为单数为ActiveDn,复数为ActiveDns,并且我会收到像“link_to new_dn_path”这样的愚蠢的东西. –force-plural参数似乎没有解决这个问题:

rails g scaffold_controller ActiveDns --force-plural

仍然导致控制器使用名为@active_dn的变量和使用new_dn_path的视图,带有rails 3.2.3.我正在使用rails d scaffold_controller ActiveDns删除尝试之间的文件.

这样做的正确方法是什么?

解决方法

What’s the right way to do this?

我使用inflectionsdocument不可数实体.

config/initializers/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

这是你想要的吗?

原文链接:https://www.f2er.com/ruby/273814.html

猜你在找的Ruby相关文章