質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Laravel

LaravelとはTaylor Otwellによって開発された、オープンソースなPHPフレームワークです。Laravelはシンプルで表現的なシンタックスを持ち合わせており、ウェブアプリケーション開発の手助けをしてくれます。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

Q&A

解決済

1回答

2015閲覧

Ruby on Railsでコントローラーが生成できなくなってしまいました

yusuke9814

総合スコア18

Laravel

LaravelとはTaylor Otwellによって開発された、オープンソースなPHPフレームワークです。Laravelはシンプルで表現的なシンタックスを持ち合わせており、ウェブアプリケーション開発の手助けをしてくれます。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

0グッド

1クリップ

投稿2019/02/17 05:57

前提・実現したいこと

新しくrailsでアプリを作成し、コントローラーを生成するためにrails g controller home top
のコマンドを打ったのですがエラーが出てしまい上手く行きません
以前まではエラーも出ず上手くいっていたのですが、最近docker環境でlaravelを構築したことがあり、それからエラーが出るようになってしまいました。
何卒解決方法をご教授お願いいたします。

発生している問題・エラーメッセージ 

rb:188:in `rescue in spec': Specified 'sqlite3' for database adapter, but the gem is not loaded. Add `gem 'sqlite3'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError) from /Users/yusukewatanabe/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activerecord-5.1.6.1/lib/active_record/connection_adapters/connection_specification.rb:185:in `spec' from /Users/yusukewatanabe/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activerecord-5.1.6.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:880:in `establish_connection' from /Users/yusukewatanabe/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activerecord-5.1.6.1/lib/active_record/connection_handling.rb:58:in `establish_connection' from /Users/yusukewatanabe/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activerecord-5.1.6.1/lib/active_record/railtie.rb:124:in `block (2 levels) in <class:Railtie>' from /Users/yusukewatanabe/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activesupport-5.1.6.1/lib/active_support/lazy_load_hooks.rb:69:in `instance_eval' from /Users/yusukewatanabe/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activesupport-5.1.6.1/lib/active_support/lazy_load_hooks.rb:69:in `block in execute_hook' from /Users/yusukewatanabe/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activesupport-5.1.6.1/lib/active_support/lazy_load_hooks.rb:60:in `with_execution_control' from /Users/yusukewatanabe/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activesupport-5.1.6.1/lib/active_support/lazy_load_hooks.rb:65:in `execute_hook' from /Users/yusukewatanabe/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activesupport-5.1.6.1/lib/active_support/lazy_load_hooks.rb:50:in `block in run_load_hooks' from /Users/yusukewatanabe/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activesupport-5.1.6.1/lib/active_support/lazy_load_hooks.rb:49:in `each' from /Users/yusukewatanabe/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activesupport-5.1.6.1/lib/active_support/lazy_load_hooks.rb:49:in `run_load_hooks' from /Users/yusukewatanabe/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activerecord-5.1.6.1/lib/active_record/base.rb:326:in `<module:ActiveRecord>' from /Users/yusukewatanabe/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activerecord-5.1.6.1/lib/active_record/base.rb:25:in `<top (required)>' from /Users/yusukewatanabe/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activesupport-5.1.6.1/lib/active_support/dependencies.rb:292:in `require' from /Users/yusukewatanabe/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activesupport-5.1.6.1/lib/active_support/dependencies.rb:292:in `block in require' from /Users/yusukewatanabe/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activesupport-5.1.6.1/lib/active_support/dependencies.rb:258:in `load_dependency' from /Users/yusukewatanabe/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activesupport-5.1.6.1/lib/active_support/dependencies.rb:292:in `require' from /Users/yusukewatanabe/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application.rb:356:in `active_record_configured?' from /Users/yusukewatanabe/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application.rb:273:in `disconnect_database' from /Users/yusukewatanabe/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application.rb:107:in `preload' from /Users/yusukewatanabe/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application.rb:153:in `serve' from /Users/yusukewatanabe/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run' from /Users/yusukewatanabe/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop' from /Users/yusukewatanabe/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `run' from /Users/yusukewatanabe/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>' from /Users/yusukewatanabe/.rbenv/versions/2.4.4/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:54:in `require' from /Users/yusukewatanabe/.rbenv/versions/2.4.4/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:54:in `require' from -e:1:in `<main>'

試したこと

エラーメッセージの言うようにgemfileにgem sqlite3を追加しようとしましたが、すでにありました。
そのあと、念のためbundle installを打って見ましたが、エラーは治りませんでした。

gemfile

1source 'https://rubygems.org' 2 3git_source(:github) do |repo_name| 4 repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") 5 "https://github.com/#{repo_name}.git" 6end 7 8 9# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 10gem 'rails', '~> 5.1.6', '>= 5.1.6.1' 11# Use sqlite3 as the database for Active Record 12gem 'sqlite3' 13# Use Puma as the app server 14gem 'puma', '~> 3.7' 15# Use SCSS for stylesheets 16gem 'sass-rails', '~> 5.0' 17# Use Uglifier as compressor for JavaScript assets 18gem 'uglifier', '>= 1.3.0' 19# See https://github.com/rails/execjs#readme for more supported runtimes 20# gem 'therubyracer', platforms: :ruby 21 22# Use CoffeeScript for .coffee assets and views 23gem 'coffee-rails', '~> 4.2' 24# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks 25gem 'turbolinks', '~> 5' 26# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 27gem 'jbuilder', '~> 2.5' 28# Use Redis adapter to run Action Cable in production 29# gem 'redis', '~> 4.0' 30# Use ActiveModel has_secure_password 31# gem 'bcrypt', '~> 3.1.7' 32 33# Use Capistrano for deployment 34# gem 'capistrano-rails', group: :development 35 36group :development, :test do 37 # Call 'byebug' anywhere in the code to stop execution and get a debugger console 38 gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] 39 # Adds support for Capybara system testing and selenium driver 40 gem 'capybara', '~> 2.13' 41 gem 'selenium-webdriver' 42end 43 44group :development do 45 # Access an IRB console on exception pages or by using <%= console %> anywhere in the code. 46 gem 'web-console', '>= 3.3.0' 47 gem 'listen', '>= 3.0.5', '< 3.2' 48 # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 49 gem 'spring' 50 gem 'spring-watcher-listen', '~> 2.0.0' 51end 52 53# Windows does not include zoneinfo files, so bundle the tzinfo-data gem 54gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 55

補足情報(FW/ツールのバージョンなど)

ここにより詳細な情報を記載してください。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

Gemfile の中に以下の記述があると思います。

gem 'sqlite3'

これを以下のように修正して、bundle install を行って下さい。その後、rails g controller をしてみてください。

gem 'sqlite3', '~> 1.3.6'

投稿2019/02/17 06:09

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

yusuke9814

2019/02/17 06:12

回答ありがとうございます。 教えていただいた通り、試して見ましたがまた同じエラーが出てしまいます.
退会済みユーザー

退会済みユーザー

2019/02/17 06:21

申し訳ございません。エラーメッセージをよく読んでいませんでした。 Ubuntu (Debian) ならば `libsqlite3-dev` を、CentOS ならば `sqlite-devel` を `apt` や `yum` でインストールし、それから `bundle install` し直してみたらどうなりますでしょうか。
yusuke9814

2019/02/17 06:30

すみませんありがとうございます、osはmacなのですが解決方法はございますでしょうか?
退会済みユーザー

退会済みユーザー

2019/02/17 06:37

よく考えたら `bundle install` は通っているんですね。そうだとしたら先程の方法は関係ないと思いますので撤回します。 Rails のバージョンおよび Ruby のバージョンはいくつでしょうか(ログに書いてはありますが、念のため)。
yusuke9814

2019/02/17 06:45 編集

それぞれ rails -v, ruby -vで rails が Rails 5.1.6.1 ruby が 2.4.4p296 (2018-03-28 revision 63013) [x86_64-darwin17] とでております
退会済みユーザー

退会済みユーザー

2019/02/17 07:04

二転三転して申し訳ございません。 同様の環境で同様のエラーが発生しましたが、最初に示したように gem 'sqlite3', '~> 1.3.6' と書き換えて bundle install をし直したらこちらでは正しく生成されました。 `bundle exec rails g controller` で生成されていますでしょうか。
yusuke9814

2019/02/17 07:17

申し訳ございません、大変失礼いたしました、以前編集していたrailsアプリのほうを変えていました。 お時間を奪ってしまい申し訳ございません。 ご指摘の通り、書き換えてbundle installしてみたところ [!] There was an error parsing `Gemfile`: dependency name must be a String, was [<Bundler::Dependency type=:runtime name="rails" requirements="~> 5.1.6, >= 5.1.6.1">, <Bundler::Dependency type=:runtime name="sqlite3" requirements="~> 1.3.6">]. Bundler cannot continue. # from /Users/yusukewatanabe/Desktop/rails_project/tutoapp3/Gemfile:12 # ------------------------------------------- # # Use sqlite3 as the database for Active Record > gem gem 'sqlite3', '~> 1.3.6' # # Use Puma as the app server # ------------------------------------------- このようなメッセージが出てきてしまいました.....
退会済みユーザー

退会済みユーザー

2019/02/17 07:18

gem gem 'sqlite3', '~> 1.3.6' ではなく gem 'sqlite3', '~> 1.3.6' として bundle install しなおしてみてください。
yusuke9814

2019/02/17 07:22 編集

失礼いたしました、上記のエラー解決できました bundle install成功し,bundle exec rails g controllerしたのですが rails aborted! Don't know how to build task 'exec' (See the list of available tasks with `rake --tasks`) /Users/yusukewatanabe/Desktop/rails_project/tutoapp3/bin/rails:9:in `require' /Users/yusukewatanabe/Desktop/rails_project/tutoapp3/bin/rails:9:in `<top (required)>' /Users/yusukewatanabe/Desktop/rails_project/tutoapp3/bin/spring:15:in `<top (required)>' bin/rails:3:in `load' bin/rails:3:in `<main>' (See full trace by running task with --trace) のエラーが出てしまいました
退会済みユーザー

退会済みユーザー

2019/02/17 07:26

入力したコマンドをコピペしてもらえるでしょうか。 あるいは、以下のように正しく入力されているでしょうか($ 記号はプロンプトを表します)。 $ bundle exec rails g controller home top
yusuke9814

2019/02/17 07:27

すみません、先ほどのはコマンドのミスでした申し訳ございません ちゃんとご指摘の通りbundle exec rails g controllerを打ったら下のエラーが出てきてしまいました rails aborted! Don't know how to build task 'exec' (See the list of available tasks with `rake --tasks`) /Users/yusukewatanabe/Desktop/rails_project/tutoapp3/bin/rails:9:in `require' /Users/yusukewatanabe/Desktop/rails_project/tutoapp3/bin/rails:9:in `<top (required)>' /Users/yusukewatanabe/Desktop/rails_project/tutoapp3/bin/spring:15:in `<top (required)>' bin/rails:3:in `load' bin/rails:3:in `<main>' (See full trace by running task with --trace) YusukenoMacBook-Pro:tutoapp3 yusukewatanabe$ bundle exec rails g controller Running via Spring preloader in process 33728 Usage: rails generate controller NAME [action action] [options] Options: [--skip-namespace], [--no-skip-namespace] # Skip namespace (affects only isolated applications) [--skip-routes], [--no-skip-routes] # Don't add routes to config/routes.rb. [--helper], [--no-helper] # Indicates when to generate helper # Default: true [--assets], [--no-assets] # Indicates when to generate assets # Default: true -e, [--template-engine=NAME] # Template engine to be invoked # Default: erb -t, [--test-framework=NAME] # Test framework to be invoked # Default: test_unit Asset options: -j, [--javascripts], [--no-javascripts] # Generate JavaScripts # Default: true -y, [--stylesheets], [--no-stylesheets] # Generate Stylesheets # Default: true -je, [--javascript-engine=JAVASCRIPT_ENGINE] # Engine for JavaScripts # Default: coffee -se, [--stylesheet-engine=STYLESHEET_ENGINE] # Engine for Stylesheets # Default: scss Runtime options: -f, [--force] # Overwrite files that already exist -p, [--pretend], [--no-pretend] # Run but do not make any changes -q, [--quiet], [--no-quiet] # Suppress status output -s, [--skip], [--no-skip] # Skip files that already exist Description: Stubs out a new controller and its views. Pass the controller name, either CamelCased or under_scored, and a list of views as arguments. To create a controller within a module, specify the controller name as a path like 'parent_module/controller_name'. This generates a controller class in app/controllers and invokes helper, template engine, assets, and test framework generators. Example: `rails generate controller CreditCards open debit credit close` CreditCards controller with URLs like /credit_cards/debit. Controller: app/controllers/credit_cards_controller.rb Test: test/controllers/credit_cards_controller_test.rb Views: app/views/credit_cards/debit.html.erb [...] Helper: app/helpers/credit_cards_helper.rb
yusuke9814

2019/02/17 07:29

度々すみません、bundle exec rails g controller home topで打ったら生成されました bundle exec rails g controller だけで打っていました。初歩的なミスで申し訳ございません。
退会済みユーザー

退会済みユーザー

2019/02/17 07:29

作成するコントローラの名前が指定されていないようです。 質問文のとおりならば、以下のように正しく入力してみて下さい。 $ bundle exec rails g controller home top
yusuke9814

2019/02/17 07:31

以後落ち着いて、コードを打つことを心がけます 長い時間お力添えいただき、誠にありがとうございました。
退会済みユーザー

退会済みユーザー

2019/02/17 07:33

良かったです。 質問の際には面倒でも、 ・バージョン番号 ・実行したコマンドをそのままで(コピペで) ・エラーメッセージも極力そのままで(長くてもよいのでコピペで、個人情報など隠すべきところは隠して) を書いておくと解決が早いかと思います。
yusuke9814

2019/02/17 07:37

アドバイスありがとうございます、大変わかりにく質問を繰り返してしまい申し訳ございませんでした。 ご親切に本当にありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問