我完全是Ruby的新手,我正在按照Michael Hartl的教程进行操作。 在第2章,第49页中,书中指出:
rails generate scaffold User name:string email:string
执行此操作后,应用程序显示:
C:\demo_app>rails generate scaffold User name:string email:string
C:/demo_app/config/environments/development.rb:1:in `<top (required)>': undefine
d method `configure' for #<DemoApp::Application:0x35d3d98> (NoMethodError)
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-
3.2.3/lib/active_support/dependencies.rb:251:in `require'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-
3.2.3/lib/active_support/dependencies.rb:251:in `block in require'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-
3.2.3/lib/active_support/dependencies.rb:236:in `load_dependency'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-
3.2.3/lib/active_support/dependencies.rb:251:in `require'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.3
/lib/rails/engine.rb:571:in `block in <class:Engine>'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.3
/lib/rails/initializable.rb:30:in `instance_exec'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.3
/lib/rails/initializable.rb:30:in `run'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.3
/lib/rails/initializable.rb:55:in `block in run_initializers'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.3
/lib/rails/initializable.rb:54:in `each'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.3
/lib/rails/initializable.rb:54:in `run_initializers'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.3
/lib/rails/application.rb:136:in `initialize!'
from C:/demo_app/config/environment.rb:5:in `<top (required)>'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.3
/lib/rails/application.rb:103:in `require'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.3
/lib/rails/application.rb:103:in `require_environment!'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.3
/lib/rails/commands.rb:25:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
我已经使用了捆绑安装,捆绑更新,安装了新版本(和旧版本)的宝石...... 有人可以让我找出错误吗? 或者一种避免这种错误的方法,以便遵循下一步。
谢谢,
答案 0 :(得分:0)
试试这个:
bundle exec rails generate scaffold User name:string email:string
答案 1 :(得分:0)
我解决了这个问题。 步骤是:
development.rb
DemoApp::Application.configure do
后来当我尝试执行rails generate scaffold User name:string email:string
时,我发现了另一个问题。
问题的描述是:
C:\ demo_app&gt; rails generate scaffold用户名:string email:string
调用active_record
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/acti
ve_record / dynamic_matchers.rb:50:in method_missing': undefined method
migratio
N_ERROR =&#39; for ActiveRecord :: Base:Class(NoMethodError)
最后,我删除config/environments/development.rb
中的以下行:
config.active_record.migration_error = :page_load
我在下一个答案中使用了一个混合: