0

当我尝试运行迁移时,我的 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
4

2 回答 2

1

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

$ script/generate migration AddBalanceToUsers balance:float

脚本/生成是关键。

希望它会帮助某人。

于 2012-07-06T12:03:38.250 回答
1

我通过以下步骤解决了这个问题:-

(1) 首先我通过运行“gem environment”进行检查

(2)然后我通过以下方式找到了rails可执行文件:-
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 命令时,它完美地创建了一个新的示例应用程序:-)

于 2012-07-06T12:21:16.557 回答