简体   繁体   English

Rails - 迁移突然不起作用

[英]Rails - migration suddenly doesn't work

My Rails app suddenly stopped to work when i try to run migration. 当我尝试运行迁移时,我的Rails应用程序突然停止工作。 For example: 例如:

$ 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

I use 我用

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

Ok, i founded solution. 好的,我创立了解决方案。 In rails 2 we should generate migration via other way: rails 2中,我们应该通过其他方式生成迁移:

$ script/generate migration AddBalanceToUsers balance:float

script/generate is the key. script / generate是关键。

Hope it'll help someone. 希望它能帮助别人。

I resolved this issue by following below steps :- 我按照以下步骤解决了这个问题: -

(1) First I checked by running 'gem environment' (1)首先我通过运行'宝石环境'进行检查

(2) Then I located the rails executable by :- (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 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 /红宝石/ vendor_ruby / railties /斌/导轨

(3) I appended the path to ~/.bashrc by :- (3)我通过以下方式将路径附加到〜/ .bashrc: -
abc@ubuntu:~$ echo 'export PATH=$PATH:/home/abc/.rvm/gems/ruby-1.9.3-0/gems/railties-.2.1/bin' >> ~/.bashrc abc @ ubuntu:〜$ echo'export PATH = $ PATH:/home/abc/.rvm/gems/ruby-1.9.3-0/gems/railties-.2.1/bin'>>〜/ .bashrc

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

And then when I ran the rails command, it created a new sample app perfectly :-) 然后当我运行rails命令时,它完美地创建了一个新的示例应用程序:-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM