Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
31
Help us understand the problem. What is going on with this article?
@Salinger

Rails の Model 作成時に単数形・複数形の変換がおかしい場合の対処法

More than 5 years have passed since last update.

はじめに

モデル作成時に、

単数形: corpus => 複数形: corpuses

と認識して欲しいのに、複数形と認識されてしまい、

$ bundle exec rails g model corpus name:string, doc_count:integer

のようなコマンドを実行すると、

[WARNING] The model name 'corpus' was recognized as a plural, using the singular 'corpu' instead. Override with --force-plural or setup custom inflection rules for this noun before running the generator.

というWARNINGが出て corpu というモデルが出来てしまった。
正しく Model が作成されるようにする。

誤作成したモデルの削除

下記コマンドを実行。

$ bundle exec rails destroy model courpu

変換内容の登録

config/initializers/inflections.rbを下記のように編集。

config/initializers/inflections.rb
ActiveSupport::Inflector.inflections(:en) do |inflect|
  inflect.irregular "corpus","corpuses"
end

結果の確認

無事作成できた。

$ bundle exec rails g model corpus name:string, doc_count:integer
      invoke  active_record
      create    db/migrate/20150213080836_create_corpuses.rb
      create    app/models/corpus.rb
      invoke    test_unit
      create      test/models/corpus_test.rb
      create      test/fixtures/corpuses.yml
31
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Salinger
the-room4d
データを分析してます。

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
31
Help us understand the problem. What is going on with this article?