gpt4 book ai didi

ruby-on-rails - Rails - 模型名称以 S 结尾

转载 作者:行者123 更新时间:2023-12-03 20:05:09 24 4
gpt4 key购买 nike

我有一个名为 ActiveDns 的模型.当我跑

rails g scaffold_controller ActiveDns

我收到消息

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



现在, Controller 和 View 的生成假装单数是 ActiveDn。复数是 ActiveDns ,我得到一些愚蠢的东西,比如 link_to new_dn_path . --force-plural论点似乎无法解决此问题:
rails g scaffold_controller ActiveDns --force-plural

仍然会导致 Controller 使用名为 @active_dn 的变量和 View 使用 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

这是你想要的吗?

关于ruby-on-rails - Rails - 模型名称以 S 结尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11928355/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com