Rails - NoMethodError: undefined method `configure

2019-01-27 08:14发布

I am working on a tutorial, I am trying to do step 1.4.2.

I have tried several things but none seem to work when I searched the web "NoMethodError: undefined method `configure'". I looked at all the links and several similar searches that came up but none worked.

In the book it says to do this:

# This should only be used if your Heroku deploy fails without it.
$ rake assets:precompile
$ git add .
$ git commit -m "Add precompiled assets for Heroku"

but it has not worked or i have not gotten it to work

Here is the real issue when i do

$ git push heroku master

this is the result.

james@ubuntu:~/rails_projects/first_app$ git push heroku master
Initializing repository, done.
Counting objects: 84, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (73/73), done.
Writing objects: 100% (84/84), 17.47 KiB, done.
Total 84 (delta 16), reused 0 (delta 0)

-----> Ruby app detected
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.0.0
-----> Installing dependencies using 1.5.2
   Running: bundle install --without development:test --path vendor/bundle --binstubs       vendor/bundle/bin -j4 --deployment
   Fetching gem metadata from https://rubygems.org/..........
   Fetching additional metadata from https://rubygems.org/..
   Installing minitest (4.7.5)
   Installing multi_json (1.10.1)
   Installing rake (10.3.2)
   Installing i18n (0.6.9)
   Installing thread_safe (0.3.3)
   Installing builder (3.1.4)
   Installing erubis (2.7.0)
   Installing tzinfo (0.3.39)
   Installing rack (1.5.2)
   Installing mime-types (1.25.1)
   Installing polyglot (0.3.4)
   Installing activerecord-deprecated_finders (1.0.3)
   Installing arel (4.0.2)
   Installing coffee-script-source (1.7.0)
   Installing hike (1.2.3)
   Installing execjs (2.0.2)
   Using bundler (1.5.2)
   Installing thor (0.19.1)
   Installing rails_serve_static_assets (0.0.2)
   Installing tilt (1.4.1)
   Installing rails_stdout_logging (0.0.3)
   Installing sass (3.2.19)
   Installing activesupport (4.0.5)
   Installing rack-test (0.6.2)
   Installing treetop (1.4.15)
   Installing json (1.8.1)
   Installing coffee-script (2.2.0)
   Installing rails_12factor (0.0.2)
   Installing sprockets (2.11.0)
   Installing activemodel (4.0.5)
   Installing jbuilder (1.0.2)
   Installing rdoc (3.12.2)
   Installing actionpack (4.0.5)
   Installing uglifier (2.5.0)
   Installing mail (2.5.4)
   Installing sdoc (0.3.20)
   Installing sprockets-rails (2.0.1)
   Installing activerecord (4.0.5)
   Installing railties (4.0.5)
   Installing actionmailer (4.0.5)
   Installing coffee-rails (4.0.1)
   Installing jquery-rails (3.0.4)
   Installing sass-rails (4.0.3)
   Installing turbolinks (1.1.1)
   Installing rails (4.0.5)
   Installing pg (0.15.1)
   Your bundle is complete!
   Gems in the groups development and test were not installed.
   It was installed into ./vendor/bundle
   Post-install message from rdoc:
   Depending on your version of ruby, you may need to install ruby rdoc/ri data:
   <= 1.8.6 : unsupported
   = 1.8.7 : gem install rdoc-data; rdoc-data --install
   = 1.9.1 : gem install rdoc-data; rdoc-data --install
   >= 1.9.2 : nothing to do! Yay!
   Bundle completed (36.13s)
   Cleaning up the bundler cache.
-----> Writing config/database.yml to read from DATABASE_URL
-----> Preparing app for Rails asset pipeline
   Running: rake assets:precompile
   rake aborted!
   NoMethodError: undefined method `configure' for #  <FirstApp::Application:0x007f74b12b4cb0>
   /tmp/build_be175c11-67be-427d-9e11-526ec2b315c1/config/environments/production.rb:1:in `<top (required)>'
   /tmp/build_be175c11-67be-427d-9e11-526ec2b315c1/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:229:in `require'
   /tmp/build_be175c11-67be-427d-9e11-526ec2b315c1/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:229:in `block in require'
   /tmp/build_be175c11-67be-427d-9e11-526ec2b315c1/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:214:in `load_dependency'
   /tmp/build_be175c11-67be-427d-9e11-526ec2b315c1/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:229:in `require'
   /tmp/build_be175c11-67be-427d-9e11-526ec2b315c1/vendor/bundle/ruby/2.0.0/gems/railties-4.0.5/lib/rails/engine.rb:591:in `block (2 levels) in <class:Engine>'
   /tmp/build_be175c11-67be-427d-9e11-526ec2b315c1/vendor/bundle/ruby/2.0.0/gems/railties-4.0.5/lib/rails/engine.rb:590:in `each'
   /tmp/build_be175c11-67be-427d-9e11-526ec2b315c1/vendor/bundle/ruby/2.0.0/gems/railties-4.0.5/lib/rails/engine.rb:590:in `block in <class:Engine>'
   /tmp/build_be175c11-67be-427d-9e11-526ec2b315c1/vendor/bundle/ruby/2.0.0/gems/railties-4.0.5/lib/rails/initializable.rb:30:in `instance_exec'
   /tmp/build_be175c11-67be-427d-9e11-526ec2b315c1/vendor/bundle/ruby/2.0.0/gems/railties-4.0.5/lib/rails/initializable.rb:30:in `run'
   /tmp/build_be175c11-67be-427d-9e11-526ec2b315c1/vendor/bundle/ruby/2.0.0/gems/railties-4.0.5/lib/rails/initializable.rb:55:in `block in run_initializers'
   /tmp/build_be175c11-67be-427d-9e11-526ec2b315c1/vendor/bundle/ruby/2.0.0/gems/railties-4.0.5/lib/rails/initializable.rb:44:in `each'
   /tmp/build_be175c11-67be-427d-9e11-526ec2b315c1/vendor/bundle/ruby/2.0.0/gems/railties-4.0.5/lib/rails/initializable.rb:44:in `tsort_each_child'
   /tmp/build_be175c11-67be-427d-9e11-526ec2b315c1/vendor/bundle/ruby/2.0.0/gems/railties-4.0.5/lib/rails/initializable.rb:54:in `run_initializers'
   /tmp/build_be175c11-67be-427d-9e11-526ec2b315c1/vendor/bundle/ruby/2.0.0/gems/railties-4.0.5/lib/rails/application.rb:215:in `initialize!'
   /tmp/build_be175c11-67be-427d-9e11-526ec2b315c1/config/environment.rb:5:in `<top (required)>'
   /tmp/build_be175c11-67be-427d-9e11-526ec2b315c1/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:229:in `require'
   /tmp/build_be175c11-67be-427d-9e11-526ec2b315c1/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:229:in `block in require'
   /tmp/build_be175c11-67be-427d-9e11-526ec2b315c1/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:214:in `load_dependency'
   /tmp/build_be175c11-67be-427d-9e11-526ec2b315c1/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:229:in `require'
   /tmp/build_be175c11-67be-427d-9e11-526ec2b315c1/vendor/bundle/ruby/2.0.0/gems/railties-4.0.5/lib/rails/application.rb:189:in `require_environment!'
   /tmp/build_be175c11-67be-427d-9e11-526ec2b315c1/vendor/bundle/ruby/2.0.0/gems/railties-4.0.5/lib/rails/application.rb:250:in `block in run_tasks_blocks'
   /tmp/build_be175c11-67be-427d-9e11-526ec2b315c1/vendor/bundle/ruby/2.0.0/gems/sprockets-rails-2.0.1/lib/sprockets/rails/task.rb:54:in `block (2 levels) in define'
   Tasks: TOP => environment
   (See full trace by running task with --trace)
 !
 !     Precompiling assets failed.
 !

 !     Push rejected, failed to compile Ruby app

To git@heroku.com:shielded-mountain-9814.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@heroku.com:shielded-mountain-9814.git'

3条回答
相关推荐>>
2楼-- · 2019-01-27 08:41

I resolved it by doing solution that other similar problem following URL.

Error launching Rails server: undefined method 'configure'

target file:

config/environments/production.rb
查看更多
戒情不戒烟
3楼-- · 2019-01-27 08:46

I had the same problems. Here is my fix:

  • Check app/config/initializers/development.rb and app/config/initializers/production.rb files. Make sure to change "Rails.application.configure do" to "FirstApp::Application.configure do".

After this add, commit and push to heroku will give you another error. Something about dump schema. You can find the explanation here: Cannot run any commands on my heroku app (migrate, console, etc).

  • Quick fix for that is to go to app/config/initializers/production.rb file and remove or comment out the line "config.dump_schema_after_migration"

Now add,commit and push that to heroku. It should work!!!

查看更多
Ridiculous、
4楼-- · 2019-01-27 08:59

I had this exact same issue just recently when setting up someone's computer for the Rails Tutorial after reformatting it for them. I was using the RailsInstaller.com Windows executable to install Rails on Windows 7, but I imagine the actual cause of, and solution to, the error is the same on Linux/OS X.

The problem in my case was that the current RailsInstaller executable installs Rails 4.1.4 (if there's a way to choose which version during the installation, I didn't see it). The RailsTutorial.org tutorial is meant to work with Rails 4.0.8, at least until Mr. Hartl updates it.

Updating your Gemfile in your project directory to use Rails 4.0.8 after creating the first_app project with rails new first_app won't fix the issue, because the problem occurs during the generation of the app/config/initializers/development.rb file which, by default, uses the newest version of Rails that's installed in your local repository.

I'm still mostly a novice to Rails so I don't know what changed, or why, but some update between Rails 4.0.8 and Rails 4.1.4 caused development.rb (and production.rb) to be generated with different syntax.

Making the change to the first line of those files to say FirstApp::Application.configure.do instead of Rails.application.configure.do, as others have suggested, will fix the compile error. However, having to manually change that line for every project didn't feel right to me.

I was able to make it generate the file correctly in two different ways:

1) Create the rails project specifying the version of Rails to use surrounded by underscores. For example, rails _4.0.8_ new first_app. You have to have that version of Rails installed for it work, obviously. You can see all versions of that gem that are installed using the command gem list -d rails. If you don't have the correct version, use gem install rails --version 4.0.8 to install it.

2) Navigate to the directory from which you'd run the rails new command when starting a new project, and from there manually uninstall from the local gem repository any versions of Rails and its dependencies above version 4.0.8. To do this, you use the command gem uninstall <gem name> --version <version number>. You could also use that command without including the version parameter, then use gem install rails --version 4.0.8 afterwards, which will install Rails and the matching version of its dependencies as well.

This was more time consuming but it's what I ended up doing. In my case, the gems I did this for were actionmailer, actionpack, activemodel, activerecord, activesupport, rails, and railties. Once the highest version for all of those gems was 4.0.8, generating a new project used Rails 4.0.8 by default and development.rb was created using the correct syntax.

One thing to mention for RVM users (I don't use it myself, since I'm on Windows, so I didn't test this): Double check which version of Rails RVM is set to use in your root development directory (the directory you'd be in when typing rails new), since that's the version that it will use when generating a new project. Even if you set RVM to use Rails 4.0.8 once inside your new project folder, it won't fix the issue since the files themselves were still generated with whatever version of Rails RVM is using in the root directory.

Again, I'm still a novice to Rails so hopefully someone more knowledgeable than I can explain what's going on with the changes to development/production.rb between Rails 4.0.8 and 4.1.4. In the meantime, though, if you're trying to get set up for the RailsTutorial.org book and are encountering this error, these are two possible methods to fix it.

查看更多
登录 后发表回答