gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 08:59:07 25 4
gpt4 key购买 nike

我正在学习Rails 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 console时出现错误

当我在控制台上写一个单词“ Article ”时,它会在上面引发错误,但是当删除article.rb文件中的这一行 mount_uploader :image, ImageUploader时,它可以正常工作。

恢复该行后,错误再次出现。因此看来错误是由那条线引起的,但我不确定。

任何人都可以解决此问题,请...

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

最佳答案

我知道这已经晚了几个月,但是我自己偶然发现了这个问题。我的解决方案是粘贴

require 'carrierwave/orm/activerecord'



进入config / environment.rb文件。只需将其附加在末尾即可。

我的环境:
Ruby 2.1.2p95;
Rails 4.1.7;
载波-0.10.0

关于ruby-on-rails-4 - Rails:NameError:未初始化的常量Article::ImageUploader在Rails 4.1.5上使用Carrierwave时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25712027/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com