11
8

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 generate model 時の複数形と単数形について

Last updated at Posted at 2014-07-18

rails にて
rails generate model ~~~

を実行する際に、モデル名として単数形と複数形を指定した時に、生成されるモデルクラスのクラス名が異なる。

単数形指定

% rails generate model test
      invoke  active_record
      create    db/migrate/20140718110429_create_tests.rb
      create    app/models/test.rb
      invoke    test_unit
      create      test/models/test_test.rb
      create      test/fixtures/tests.yml

複数形指定

% rails generate model tests
      invoke  active_record
      create    db/migrate/20140718110452_create_tests.rb
      create    app/models/tests.rb
      invoke    test_unit
      create      test/models/tests_test.rb
      create      test/fixtures/tests.yml

上記のように、生成されるモデル名が複数形か単数形かで異なる。

微妙な違いだが、モデル名が想定と違っており、少しハマったのでので注意したい。

個人的にはモデルの生成は全て単数形でやるのが面倒がなくて良いかと。

作業中に気になって調べたので、備忘録的に書き残す。

11
8
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
11
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?