Rails - NoMethodError:#<FirstApp 的未定义方法`configure' [英] Rails - NoMethodError: undefined method `configure' for #<FirstApp

查看:42
本文介绍了Rails - NoMethodError:#<FirstApp 的未定义方法`configure'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写教程,我正在尝试执行步骤 1.4.2.

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

我尝试了几件事情,但当我在网上搜索NoMethodError: undefined method `configure'"时,似乎没有任何事情能奏效.我查看了所有链接和几个类似的搜索,但都没有奏效.

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.

书中说要这样做:

# 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

这是结果.

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'

推荐答案

我最近在为某人重新格式化后为 Rails 教程设置计算机时遇到了完全相同的问题.我正在使用 RailsInstaller.com Windows 可执行文件在 Windows 7 上安装 Rails,但我想在 Linux/OS X 上错误的实际原因和解决方案是相同的.

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.

我的问题是当前的 RailsInstaller 可执行文件安装了 Rails 4.1.4(如果在安装过程中可以选择哪个版本,我没有看到).RailsTutorial.org 教程旨在使用 Rails 4.0.8,至少在 Hartl 先生更新之前是这样.

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.

在使用 rails new first_app 创建 first_app 项目后更新项目目录中的 Gemfile 以使用 Rails 4.0.8 不会解决问题,因为问题发生在 app/config/initializers/development.rb 文件,默认情况下,使用安装在本地存储库中的最新版本的 Rails.

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.

我仍然是 Rails 的新手,所以我不知道发生了什么变化,或者为什么,但是 Rails 4.0.8 和 Rails 4.1.4 之间的一些更新导致生成 development.rb(和 production.rb)使用不同的语法.

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.

将这些文件的第一行更改为 FirstApp::Application.configure.do 而不是 Rails.application.configure.do,就像其他人一样建议,将修复编译错误.但是,我觉得必须为每个项目手动更改该行并不合适.

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) 创建 rails 项目,指定要用下划线包围的 Rails 版本.例如,rails _4.0.8_ new first_app.显然,您必须安装该版本的 Rails 才能正常工作.您可以查看使用命令 gem list -d rails 安装的该 gem 的所有版本.如果您没有正确的版本,请使用 gem install rails --version 4.0.8 进行安装.

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) 导航到您在启动新项目时运行 rails new 命令的目录,然后从那里手动从本地 gem 存储库卸载任何版本的 Rails 及其依赖项版本 4.0.8.为此,您可以使用命令 gem uninstall --version <版本号>.您也可以使用该命令而不包含 version 参数,然后使用 gem install rails --version 4.0.8,这将安装 Rails 及其依赖项的匹配版本.

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.

这更耗时,但我最终还是这样做了.在我的例子中,我这样做的重点是 actionmailer、actionpack、activemodel、activerecord、activesupport、rails、railties.一旦所有这些 gem 的最高版本是 4.0.8,生成一个默认使用 Rails 4.0.8 的新项目,并使用正确的语法创建 development.rb.

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.

对于 RVM 用户要提的一件事(我自己不使用它,因为我在 Windows 上,所以我没有对此进行测试):仔细检查 Rails RVM 的版本设置为在您的根开发目录(键入 rails new 时所在的目录)中使用,因为这是生成新项目时将使用的版本.即使您在新项目文件夹中将 RVM 设置为使用 Rails 4.0.8,也无法解决问题,因为文件本身仍然是使用根目录中使用的任何版本的 Rails RVM 生成的.

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.

同样,我仍然是 Rails 的新手,所以希望有人比我更了解 Rails 4.0.8 和 4.1.4 之间的 development/production.rb 变化.不过,与此同时,如果您正在尝试为 RailsTutorial.org 书籍进行设置并遇到此错误,则可以通过以下两种方法来修复它.

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.

这篇关于Rails - NoMethodError:#&lt;FirstApp 的未定义方法`configure'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆