Heroku + Devise + Paperclip + Amazon S3エラー

I’m following the guide here: http://webtempest.com/how-to-allow-image-uploads-in-rails-on-heroku/
And I am getting an error whenever I attempt to run rails server –
below I’ve added the files that were changed with their respective
code. I don’t understand however where the error is coming
from:

エラー

[email protected]:~/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

user.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 (blank at the moment because I can’t
even get to the next step on the guide since rails is running into
an error)

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(IMHO)では使用できません。

Try using : :s3_credentials =>
"#{Rails.root}/config/s3.yml"

Instead of :s3_credentials =>
"#{RAILS_ROOT}/config/s3.yml"

コメントする

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です