当前位置: 动力学知识库 > 问答 > 编程问答 >

Rails 3.2 puts 's' behind generated scaffold

问题描述:

I'm wondering if i can generate a scaffold without getting that annyoing s after all scaffolds.

For example, when I run rails generate scaffold product, rails

generates a scaffold called products.

网友答案:

You can modify config/initializers/inflections.rb and provide custom Inflections for words that you want to pluralize/singularize differently. Something like:

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

would make it so rails g scaffold Product ... wouldn't pluralize the table name and controller name.

However, I would advise against doing this en masse, or just because you don't like pluralization. One of Rails strengths is "Convention over Configuration", and like in several cases, if you're not following the convention, it will be more trouble than it's worth in the long run.

网友答案:

May be you should think about changing your config/initializers/inflections.rb file. Learn more by links below:

  • Pluralizations and Singularizations (Inflections) in Rails 3
  • ActiveSupport::Inflector
分享给朋友:
您可能感兴趣的文章:
随机阅读: