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

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

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

Deviseとは、Ruby-on-Railsの認証機能を追加するプラグインです。

Flash

Flashは、Webページにアニメーション、ビデオ、また対話型のアプリケーションを埋め込むためにAdobe社が提供しているクロスプラットフォームのインターネットマルチメディアランタイムです。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

RubyGems

RubyGemsはRubyによるプログラミングのためのパッケージマネジメントツールです。ユーザはこれを使用することで、Rubyライブラリのダウンロードやアップデートや、依存関係の自動解決が可能になります。

Ruby on Rails

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

Q&A

解決済

1回答

1342閲覧

Cloud9で「rails g devise:views」を実行するとエラーが発生

nem96

総合スコア8

Devise

Deviseとは、Ruby-on-Railsの認証機能を追加するプラグインです。

Flash

Flashは、Webページにアニメーション、ビデオ、また対話型のアプリケーションを埋め込むためにAdobe社が提供しているクロスプラットフォームのインターネットマルチメディアランタイムです。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

RubyGems

RubyGemsはRubyによるプログラミングのためのパッケージマネジメントツールです。ユーザはこれを使用することで、Rubyライブラリのダウンロードやアップデートや、依存関係の自動解決が可能になります。

Ruby on Rails

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

0グッド

0クリップ

投稿2021/06/07 01:09

編集2021/06/07 01:58

railsでdeviseを使うにあたりターミナルで、以下を実行しました。

terminal

1rails g devise:views

しかしこのように「requiredが定義されていない」というエラーが出てしまいます。

terminal

1/home/ec2-user/environment/rails_projects/recipegram/config/environments/development.rb:55:in `<top (required)>': undefined local variable or method `config' for main:Object (NameError) 2 from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activesupport-5.0.7.2/lib/active_support/dependencies.rb:293:in `require' 3 from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activesupport-5.0.7.2/lib/active_support/dependencies.rb:293:in `block in require' 4 from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activesupport-5.0.7.2/lib/active_support/dependencies.rb:259:in `load_dependency' 5 from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activesupport-5.0.7.2/lib/active_support/dependencies.rb:293:in `require' 6 from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/railties-5.0.7.2/lib/rails/engine.rb:600:in `block (2 levels) in <class:Engine>' 7 from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/railties-5.0.7.2/lib/rails/engine.rb:599:in `each' 8 from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/railties-5.0.7.2/lib/rails/engine.rb:599:in `block in <class:Engine>' 9 from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/railties-5.0.7.2/lib/rails/initializable.rb:30:in `instance_exec' 10 from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/railties-5.0.7.2/lib/rails/initializable.rb:30:in `run' 11 from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/railties-5.0.7.2/lib/rails/initializable.rb:55:in `block in run_initializers' 12 from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:228:in `block in tsort_each' 13 from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component' 14 from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from' 15 from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:431:in `each_strongly_connected_component_from' 16 from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:421:in `block in each_strongly_connected_component_from' 17 from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/railties-5.0.7.2/lib/rails/initializable.rb:44:in `each' 18 from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/railties-5.0.7.2/lib/rails/initializable.rb:44:in `tsort_each_child' 19 from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:415:in `call' 20 from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:415:in `each_strongly_connected_component_from' 21 from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:349:in `block in each_strongly_connected_component' 22 from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `each' 23 from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `call' 24 from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `each_strongly_connected_component' 25 from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:226:in `tsort_each' 26 from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:205:in `tsort_each' 27 from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/railties-5.0.7.2/lib/rails/initializable.rb:54:in `run_initializers' 28 from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/railties-5.0.7.2/lib/rails/application.rb:352:in `initialize!' 29 from /home/ec2-user/environment/rails_projects/recipegram/config/environment.rb:5:in `<top (required)>' 30 from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activesupport-5.0.7.2/lib/active_support/dependencies.rb:293:in `require' 31 from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activesupport-5.0.7.2/lib/active_support/dependencies.rb:293:in `block in require' 32 from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activesupport-5.0.7.2/lib/active_support/dependencies.rb:259:in `load_dependency' 33 from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activesupport-5.0.7.2/lib/active_support/dependencies.rb:293:in `require' 34 from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/spring-2.1.1/lib/spring/application.rb:106:in `preload' 35 from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/spring-2.1.1/lib/spring/application.rb:157:in `serve' 36 from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/spring-2.1.1/lib/spring/application.rb:145:in `block in run' 37 from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/spring-2.1.1/lib/spring/application.rb:139:in `loop' 38 from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/spring-2.1.1/lib/spring/application.rb:139:in `run' 39 from /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/spring-2.1.1/lib/spring/application/boot.rb:19:in `<top (required)>' 40 from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require' 41 from /home/ec2-user/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require' 42 from -e:1:in `<main>'

原因となっているであろう「development.rb」ファイルを見ても、なぜ55行目がエラーになるのかどうしても分かりません。

development.rb

rails

1 2Rails.application.configure do 3 # Settings specified here will take precedence over those in config/application.rb. 4 5 # In the development environment your application's code is reloaded on 6 # every request. This slows down response time but is perfect for development 7 # since you don't have to restart the web server when you make code changes. 8 config.cache_classes = false 9 10 # Do not eager load code on boot. 11 config.eager_load = false 12 13 # Show full error reports. 14 config.consider_all_requests_local = true 15 16 # Enable/disable caching. By default caching is disabled. 17 if Rails.root.join('tmp/caching-dev.txt').exist? 18 config.action_controller.perform_caching = true 19 20 config.cache_store = :memory_store 21 config.public_file_server.headers = { 22 'Cache-Control' => 'public, max-age=172800' 23 } 24 else 25 config.action_controller.perform_caching = false 26 27 config.cache_store = :null_store 28 end 29 30 # Don't care if the mailer can't send. 31 config.action_mailer.raise_delivery_errors = false 32 33 config.action_mailer.perform_caching = false 34 35 # Print deprecation notices to the Rails logger. 36 config.active_support.deprecation = :log 37 38 # Raise an error on page load if there are pending migrations. 39 config.active_record.migration_error = :page_load 40 41 # Debug mode disables concatenation and preprocessing of assets. 42 # This option may cause significant delays in view rendering with a large 43 # number of complex assets. 44 config.assets.debug = true 45 46 # Suppress logger output for asset requests. 47 config.assets.quiet = true 48 49 # Raises error for missing translations 50 # config.action_view.raise_on_missing_translations = true 51 52 # Use an evented file watcher to asynchronously detect changes in source code, 53 # routes, locales, etc. This feature depends on the listen gem. 54 config.file_watcher = ActiveSupport::EventedFileUpdateChecker 55end 56config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

ちなみにGemfileの編集とインストール、デフォルトURLの指定やroot_urlの指定、flashメッセージの設定はすでにしています。

routes.rb

rails

1Rails.application.routes.draw do 2 root to: "home#index" 3end

application.html.erb

rails

1<!DOCTYPE html> 2<html> 3 <head> 4 <title></title> 5 <%= csrf_meta_tags %> 6 7 <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> 8 <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> 9 </head> 10 11 <body> 12 <% if flash[:notice] %> 13 <div class="notification is-info"> 14 <p class="notice"><%= notice %></p> 15 </div> 16 <% end %> 17 18 <% if flash[:alert] %> 19 <div class="notification is-danger"> 20 <p class="alert"><%= alert %></p> 21 </div> 22 <% end %> 23 <%= yield %> 24 </body> 25</html>

お手上げ状態なので、アドバイスいただけると幸いです。

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

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

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

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

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

guest

回答1

0

ベストアンサー

.../environments/development.rb:55:in <top (required)>': undefined local variable or method config' for main:Object (NameError)

このエラーの読み方は
「トップレベル(≒グローバルスコープ)にconfigメソッドもしくはローカル変数が見つからない」
です。

development.rbの55行目を見るとendの直後に

config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

があります

他の行と同様に
Rails.application.configure doendの中に入れる必要があります。

投稿2021/06/07 07:36

編集2021/06/07 07:37
asm

総合スコア15147

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

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

nem96

2021/06/07 11:10

アドバイスいただきありがとうございます。 おっしゃる通りendの中に記述したらエラー解消できました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問