ruby-on-rails-4 – NameError:未初始化的常量Article :: ImageUploader在轨道上使用Carrierwave时4.1.5

前端之家收集整理的这篇文章主要介绍了ruby-on-rails-4 – NameError:未初始化的常量Article :: ImageUploader在轨道上使用Carrierwave时4.1.5前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在学习轨道4.1.5

我收到这个错误

2.1.1 :008 > Article
NameError: uninitialized constant Article::ImageUploader
    from /Volumes/disk0s4/www/rails/blog/app/models/article.rb:4:in `<class:Article>'
    from /Volumes/disk0s4/www/rails/blog/app/models/article.rb:1:in `<top (required)>'
    from (irb):8
    from /Users/didin/.rvm/gems/ruby-2.1.1/gems/railties-4.1.5/lib/rails/commands/console.rb:90:in `start'
    from /Users/didin/.rvm/gems/ruby-2.1.1/gems/railties-4.1.5/lib/rails/commands/console.rb:9:in `start'
    from /Users/didin/.rvm/gems/ruby-2.1.1/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:69:in `console'
    from /Users/didin/.rvm/gems/ruby-2.1.1/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /Users/didin/.rvm/gems/ruby-2.1.1/gems/railties-4.1.5/lib/rails/commands.rb:17:in `<top (required)>'
    from /Volumes/disk0s4/www/rails/blog/bin/rails:8:in `<top (required)>'
    from /Users/didin/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /Users/didin/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from -e:1:in `<main>'

我的文件:article.rb

class Article < ActiveRecord::Base    
    validates_presence_of :title,:body
    belongs_to :user
    mount_uploader :image,ImageUploader
end

运行rails控制台时出错

当我在控制台上写一个词“文章”时,它会引发上面的错误,但是当这行line_rloader:image,Image.load的文件删除时,它工作正常.

当该行被恢复时,错误再次出现.所以似乎错误是造成这一行,但我不确定.

任何人都可以解决这个问题,请…

谢谢你的阅读和回答:-)

解决方法

我知道这是几个月后,但我自己偶然发现了这个问题.我的解决方法是粘贴

require ‘carrierwave/orm/activerecord’

进入config / environment.rb文件.最后附加它.

我的环境:Ruby 2.1.2p95;路线4.1.7;Carrierwave-0.10.0

原文链接:https://www.f2er.com/ruby/272553.html

猜你在找的Ruby相关文章