LoginSignup
0
0

More than 3 years have passed since last update.

「The name 'Todo' is either already used in your application or reserved by Ruby on Rails. Please choose an alternative and run this generator again.」エラー対処法

Last updated at Posted at 2020-02-17

$ rails g model Todo item:text
Running via Spring preloader in process 83975
      invoke  active_record
The name 'Todo' is either already used in your application or reserved by Ruby on Rails. Please choose an alternative and run this generator again.

参考ページ
https://qiita.com/tu-kun/items/4fede82431e546abd941

原因:今回作ろうとしてるRailsアプリケーションのモジュール名とモデル名が重複していたためエラーになった

1.モジュール名の変更 Todo → RailsTodo

config/application.rb
require_relative 'boot'

require 'rails/all'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

- module Todo
+ module RailsTodo
  class Application < Rails::Application
    # Initialize configuration defaults for originally generated Rails version.
    config.load_defaults 6.0

    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration can go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded after loading
    # the framework and any gems in your application.
  end
end

2.モジュール名を変更したあと、フォルダ名を変更する todo → rails_todo

  • フォルダ名はスネークケース(小文字で単語区切りが_
  • モジュール名はアッパーキャメルケース(単語区切りが大文字でそれ以外は小文字)
  • Railsにおいてアプリケーション名を表す部分はconfig/application.rbのモジュール名のことをいう

参考ページ
https://designsupply-web.com/developmentlab/4052/

エラー解消

$ rails g model Todo item:text completed:boolean
Running via Spring preloader in process 84393
      invoke  active_record
      create    db/migrate/20200216151440_create_todos.rb
      create    app/models/todo.rb
      invoke    test_unit
      create      test/models/todo_test.rb
      create      test/fixtures/todos.yml
$ rails db:migrate
== 20200216151440 CreateTodos: migrating ======================================
-- create_table(:todos)
   -> 0.0018s
== 20200216151440 CreateTodos: migrated (0.0018s) =============================
0
0
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
0
0