Rails - 迁移突然不起作用

时间:2012-07-06 11:07:25

标签: ruby-on-rails ruby

当我尝试运行迁移时,我的Rails应用程序突然停止工作。例如:

$ rails generate migration AddBalanceToUsers balance:float
/Users/serg/.rvm/gems/ree-1.8.7-head/gems/rails-2.3.5/bin/../lib/rails_generator/options.rb:32:in `default_options': undefined method `write_inheritable_attribute' for Rails::Generator::Base:Class (NoMethodError)
    from /Users/serg/.rvm/gems/ree-1.8.7-head/gems/rails-2.3.5/bin/../lib/rails_generator/base.rb:90
    from /Users/serg/.rvm/rubies/ree-1.8.7-head/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:29:in `gem_original_require'
    from /Users/serg/.rvm/rubies/ree-1.8.7-head/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:29:in `require'
    from /Users/serg/.rvm/gems/ree-1.8.7-head/gems/rails-2.3.5/bin/../lib/rails_generator.rb:34
    from /Users/serg/.rvm/rubies/ree-1.8.7-head/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:29:in `gem_original_require'
    from /Users/serg/.rvm/rubies/ree-1.8.7-head/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:29:in `require'
    from /Users/serg/.rvm/gems/ree-1.8.7-head/gems/rails-2.3.5/bin/rails:14
    from /Users/serg/.rvm/gems/ree-1.8.7-head/bin/rails:19:in `load'
    from /Users/serg/.rvm/gems/ree-1.8.7-head/bin/rails:19

我用

ree 1.8.7
rails 2.3.5 (but i also have rails 3.2.3)
RVM
OS X Lion

2 个答案:

答案 0 :(得分:1)

好的,我创立了解决方案。在 rails 2 中,我们应该通过其他方式生成迁移:

$ script/generate migration AddBalanceToUsers balance:float

script / generate 是关键。

希望它能帮到某人。

答案 1 :(得分:1)

我按照以下步骤解决了这个问题: -

(1)首先我通过运行'gem environment'来检查

(2)然后我找到了可执行的轨道: -
abc @ ubuntu:〜$ locate rails | grep -e“bin / rails $” /home/abc/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.1/bin/rails / usr / lib / ruby​​ / vendor_ruby / railties / bin / rails

(3)我将路径附加到〜/ .bashrc: - abc @ ubuntu:〜$ echo'export PATH = $ PATH:/home/abc/.rvm/gems/ruby-1.9.3-0/gems/railties-.2.1/bin'>> 〜/ .bashrc

(4)重新加载〜/ .bashrc文件: -
abc @ ubuntu:〜$。 〜/ .bashrc

然后当我运行rails命令时,它完美地创建了一个新的示例应用程序: - )