31
31

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Posted at

はじめに

モデル作成時に、

単数形: 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
31
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
31
31

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?