ruby-on-rails - Heroku + Devise + Paperclip + Amazon S3 错误

标签 ruby-on-rails heroku devise amazon-s3 paperclip

我正在按照此处的指南进行操作:http://webtempest.com/how-to-allow-image-uploads-in-rails-on-heroku/每当我尝试运行 rails server 时,我都会收到一个错误 - 下面我添加了用各自的代码更改的文件。但是我不明白错误是从哪里来的:

错误

sabiola@ubuntu:~/delta_bak$ rails server
=> Booting WEBrick
=> Rails 3.1.1 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/home/sabiola/delta_bak/app/models/user.rb:17: uninitialized constant User::RAILS_ROOT (NameError)
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/activesupport-3.1.1/lib/active_support/inflector/methods.rb:113:in `constantize'
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/activesupport-3.1.1/lib/active_support/inflector/methods.rb:112:in `each'
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/activesupport-3.1.1/lib/active_support/inflector/methods.rb:112:in `constantize'
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/devise-1.4.9/lib/devise.rb:259:in `get'
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/devise-1.4.9/lib/devise/mapping.rb:103:in `to'
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/devise-1.4.9/lib/devise/mapping.rb:98:in `modules'
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/devise-1.4.9/lib/devise/mapping.rb:115:in `routes'
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/devise-1.4.9/lib/devise/mapping.rb:84:in `initialize'
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/devise-1.4.9/lib/devise.rb:289:in `new'
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/devise-1.4.9/lib/devise.rb:289:in `add_mapping'
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/devise-1.4.9/lib/devise/rails/routes.rb:190:in `devise_for'
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/devise-1.4.9/lib/devise/rails/routes.rb:189:in `each'
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/devise-1.4.9/lib/devise/rails/routes.rb:189:in `devise_for'
    from /home/sabiola/delta_bak/config/routes.rb:4
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/actionpack-3.1.1/lib/action_dispatch/routing/route_set.rb:258:in `instance_exec'
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/actionpack-3.1.1/lib/action_dispatch/routing/route_set.rb:258:in `eval_block'
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/actionpack-3.1.1/lib/action_dispatch/routing/route_set.rb:235:in `draw'
    from /home/sabiola/delta_bak/config/routes.rb:1
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/railties-3.1.1/lib/rails/application/routes_reloader.rb:29:in `load_paths'
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/railties-3.1.1/lib/rails/application/routes_reloader.rb:29:in `each'
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/railties-3.1.1/lib/rails/application/routes_reloader.rb:29:in `load_paths'
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/railties-3.1.1/lib/rails/application/routes_reloader.rb:13:in `reload!'
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/railties-3.1.1/lib/rails/application/routes_reloader.rb:7:in `initialize'
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/activesupport-3.1.1/lib/active_support/file_update_checker.rb:32:in `call'
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/activesupport-3.1.1/lib/active_support/file_update_checker.rb:32:in `execute_if_updated'
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/railties-3.1.1/lib/rails/application/finisher.rb:63
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/railties-3.1.1/lib/rails/application/finisher.rb:64:in `call'
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/railties-3.1.1/lib/rails/application/finisher.rb:64
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/railties-3.1.1/lib/rails/initializable.rb:30:in `instance_exec'
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/railties-3.1.1/lib/rails/initializable.rb:30:in `run'
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/railties-3.1.1/lib/rails/initializable.rb:55:in `run_initializers'
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/railties-3.1.1/lib/rails/initializable.rb:54:in `each'
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/railties-3.1.1/lib/rails/initializable.rb:54:in `run_initializers'
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/railties-3.1.1/lib/rails/application.rb:96:in `initialize!'
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/railties-3.1.1/lib/rails/railtie/configurable.rb:30:in `send'
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/railties-3.1.1/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /home/sabiola/delta_bak/config/environment.rb:5
    from /home/sabiola/delta_bak/config.ru:4
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/rack-1.3.5/lib/rack/builder.rb:51:in `instance_eval'
    from /home/sabiola/.rvm/gems/ruby-1.8.7-p352/gems/rack-1.3.5/lib/rack/builder.rb:51:in `initialize'
    from /home/sabiola/delta_bak/config.ru:1:in `new'
    from /home/sabiola/delta_bak/config.ru:1

用户.rb

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me,
        :firstname, :middlename, :lastname, :discipline, :peeruser,
        :concept, :course, :comment, :academic, :photo
  has_attached_file :photo, :styles => {
        :thumb  => "100x100",
        :medium => "200x200",
        :large => "600x400"
    },
    :storage => :s3,
    :s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
    :path => ":attachment/:id/:style.:extension",
    :bucket => 'yourbucket'
end

s3.yml(目前空白,因为 Rails 遇到错误,我什至无法进入指南的下一步)

access_key_id:
secret_access_key:
bucket:

add_photo_to_users.rb

class AddPhotoToUsers < ActiveRecord::Migration
  def self.up
    add_column :users, :photo_file_name,    :string
    add_column :users, :photo_content_type, :string
    add_column :users, :photo_file_size,    :integer
    add_column :users, :photo_updated_at,   :datetime
  end

  def self.down
    remove_column :users, :photo_file_name
    remove_column :users, :photo_content_type
    remove_column :users, :photo_file_size
    remove_column :users, :photo_updated_at
  end
end

最佳答案

常量 RAILS_ROOT 已弃用,在 3.1(恕我直言)中不可用

尝试使用: :s3_credentials => "#{Rails.root}/config/s3.yml"

代替 :s3_credentials => "#{RAILS_ROOT}/config/s3.yml"

关于ruby-on-rails - Heroku + Devise + Paperclip + Amazon S3 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8109792/

相关文章:

ruby-on-rails - Devise 无法登录 Google Chrome

ruby-on-rails - Rails 3- Devise - 通过网络服务进行身份验证

android - 将 Android 应用程序连接到 Rails 服务器

ruby-on-rails - 将 mongodb 数据库迁移到 heroku

ruby-on-rails - heroku push 上的 Ruby 版本更改

ruby-on-rails - 对于 Rails 6 网站,Heroku 上的 .well-known 文件夹在哪里?

ruby-on-rails - Ruby on rails active record 查询哪个效率高

ruby-on-rails - 在 Ruby on Rails 中发送响应之前如何等待多个异步操作完成?

ruby-on-rails - 在 Rails 集成测试中更改请求环境变量

ruby-on-rails - 设计向任何电子邮件 ID 发送忘记密码的说明