我正在编写一个演示来练习" carrierwave"的宝石,它在开发ENV 中运行良好,但在部署到时失败了Heroku的
当我: heroku运行rails s 时,出现此错误:
/app/app/models/article.rb:9:in`' ;:未初始化的常量Article :: PictureUploader(NameError)
我的代码: 应用程序/模型/ article.rb
class Article < ActiveRecord::Base
belongs_to :user
has_many :comments, dependent: :destroy
has_many :likes
validates :title, presence: true, length: {maximum: 50}
validates :content, length: {minimum: 10}
self.per_page = 10
attr_accessor :floor_number
mount_uploader :picture, PictureUploader
validate :picture_size
上传/ picture_uploader.rb
class PictureUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
process resize_to_limit: [600, 600]
storage :qiniu
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def extension_white_list
%w{jpg gif png jpeg}
end
end
分贝/ schema.rb
ActiveRecord::Schema.define(version: 20150529021048) do
create_table "articles", force: :cascade do |t|
t.string "title"
t.text "content"
t.string "label"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "picture"
end
add_index "articles", ["user_id"], name: "index_articles_on_user_id"
create_table "comments", force: :cascade do |t|
t.text "content"
t.integer "article_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
end
add_index "comments", ["article_id"], name: "index_comments_on_article_id"
add_index "comments", ["user_id"], name: "index_comments_on_user_id"
create_table "likes", force: :cascade do |t|
t.integer "likes_num"
t.integer "article_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "likes", ["article_id"], name: "index_likes_on_article_id"
create_table "messages", force: :cascade do |t|
t.text "content"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "messages", ["user_id"], name: "index_messages_on_user_id"
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.string "name"
t.boolean "admin"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "users", ["email"], name: "index_users_on_email", unique: true
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
错误:
yesijiedeMacBook-Pro:blog killernova $ heroku run rails c 运行
rails c
附加到终端...向上,运行.2077 /app/app/models/article.rb:9:in<class:Article>': uninitialized constant Article::PictureUploader (NameError) from /app/app/models/article.rb:1:in
&#39; 来自/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/engine.rb:472:inblock (2 levels) in eager_load!' from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/engine.rb:471:in
每个&#39; 来自/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/engine.rb:471:inblock in eager_load!' from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/engine.rb:469:in
每个&#39; 来自/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/engine.rb:469:ineager_load!' from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/engine.rb:346:in
eager_load!&#39; 来自/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/application/finisher.rb:56:ineach' from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/application/finisher.rb:56:in
阻止&#39; 来自/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/initializable.rb:30:ininstance_exec' from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/initializable.rb:30:in
运行&#39; 来自/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/initializable.rb:55:inblock in run_initializers' from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:150:in
阻止tsort_each&#39; 来自/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:183:inblock (2 levels) in each_strongly_connected_component' from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:219:in
each_strongly_connected_component_from&#39; 来自/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:182:inblock in each_strongly_connected_component' from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:180:in
每个&#39; 来自/app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:180:ineach_strongly_connected_component' from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/tsort.rb:148:in
tsort_each&#39; 来自/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/initializable.rb:54:inrun_initializers' from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/application.rb:352:in
初始化!&#39; 来自/app/config/environment.rb:5:in<top (required)>' from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/application.rb:328:in
require_environment!&#39; 来自/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:142:inrequire_application_and_environment!' from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:67:in
console&#39; 来自/app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:39:inrun_command!' from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.2.1/lib/rails/commands.rb:17:in
&#39; 来自/ app / bin / rails:4:require' from /app/bin/rails:4:in
&#39; yesijiedeMacBook-Pro:blog killernova $
:qiqiu 是另一个宝石&#34; carrierwave-qiniu&#34;。
在localhost:3000中一切都很好,所以有人想告诉我哪里错了?谢谢!
答案 0 :(得分:1)
您是否已将app/uploaders/
提交给heroku master?
我有同样的错误,忘记将这些上传者文件添加到远程存储库