以下是rails生产控制台中的错误消息。用户是模型,错误由“a = User.new”创建。
D:\rails_proj\emclab-failed>rails c production
Loading production environment (Rails 3.1.0)
irb(main):001:0> a = User.new
←[1m←[36m (0.0ms)←[0m ←[1mSHOW TABLES←[0m
←[1m←[35m (10.0ms)←[0m describe `users`
SyntaxError: C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/attribute_methods/read.rb:91: syntax error, unexpected keyword_end
C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/attribute_methods/read.rb:93: syntax error, unexpected $end, expecting keyword_end
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/attribute_methods/read.rb:83:in `module_eval'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/attribute_methods/read.rb:83:in `define_read_method'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/attribute_methods/read.rb:42:in `define_method_attribute'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/attribute_methods/time_zone_conversion.rb:35:in `define_method_attribute'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activemodel-3.1.0/lib/active_model/attribute_methods.rb:291:in `block in define_attribute_method'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activemodel-3.1.0/lib/active_model/attribute_methods.rb:286:in `each'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activemodel-3.1.0/lib/active_model/attribute_methods.rb:286:in `define_attribute_method'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activemodel-3.1.0/lib/active_model/attribute_methods.rb:282:in `block in define_attribute_methods'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activemodel-3.1.0/lib/active_model/attribute_methods.rb:282:in `each'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activemodel-3.1.0/lib/active_model/attribute_methods.rb:282:in `define_attribute_methods'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/attribute_methods.rb:14:in `define_attribute_methods'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/attribute_methods.rb:65:in `respond_to?'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/attribute_methods/read.rb:103:in `read_attribute'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/base.rb:1774:in `attribute_for_inspect'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/base.rb:1891:in `block in inspect'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/base.rb:1889:in `collect'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/base.rb:1889:in `inspect'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/commands/console.rb:45:in `start'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/commands/console.rb:8:in `start'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'irb(main):002:0>
但是,开发中的相同命令会生成一个没有任何错误的新实例。不同之处在于生产数据库中没有数据。它是用于开发的sqlite3和用于生产的mysql 5.1.54。
Loading development environment (Rails 3.1.0)
irb(main):001:0> a = User.new
=> #<User id: nil, name: nil, email: nil, encrypted_password: nil, salt: nil, status: "active", created_at: nil, updated_at: nil, user_type: nil>
有什么想法?感谢。
答案 0 :(得分:1)
你用什么宝石用于mysql?根据{{3}},如果您正在使用mysql2 gem,则可能只需运行bundle update mysql2
。