2011-09-17 9 views
2

私のユーザモデルに搬送波ベースの画像アップロードを追加しようとしています。これは開発時にローカルで動作します。 herokuでは、イメージはs3バケットにアップロードされますが、表示されることはありません。コンソールには、アップロードされた画像がないようです。画像が適切に関連付けられていない(搬送波、霧、英雄)

イメージがs3になっている場合、それが適切に関連付けられていないのはなぜですか?

# config/initializers/carrierwave.rb 
CarrierWave.configure do |config| 

    if Rails.env.production? 
    config.fog_credentials = { 
     provider:    'AWS',    # required 
     aws_access_key_id:  ENV['S3_KEY'],  # required 
     aws_secret_access_key: ENV['S3_SECRET']  # required 
    } 

    config.fog_directory = ENV['S3_BUCKET']  # required 
    config.fog_public  = false     # optional, defaults to true 
    config.fog_attributes = { 
     'Cache-Control'=>'max-age=315576000' 
    } 

    config.storage = :fog 
    else 
    config.storage = :file 
    end 

end 

# app/uploaders/profile_picture_uploader.rb 
class ProfilePictureUploader < CarrierWave::Uploader::Base 

    def store_dir 
    "uploads/#{ model_name }/#{ mounted_as }/#{ model.id }" 
    end 

    def cache_dir 
    Rails.root.join *%w[ tmp uploads model_name ] 
    end 

    def extension_white_list 
    %w[ jpg jpeg gif png ] 
    end 

private 

    def model_name 
    @model_name ||= model.class.to_s.underscore 
    end 

end 

# app/models/user.rb 
class User < ActiveRecord::Base 

    mount_uploader :profile_picture, ProfilePictureUploader 

    devise :database_authenticatable, :registerable, 
     :recoverable, :rememberable, :trackable, :validatable, :confirmable 

    attr_accessible :email, :password, :password_confirmation, :profile_picture 

end 

# app/views/users/edit.html.haml 
%h1 Edit user 

= form_for @user do |f| 

    %h2 Profile Picture 
    - if f.object.profile_picture.present? 
    = image_tag f.object.profile_picture 
    %p= f.object.profile_picture.file.basename 

    = f.check_box :remove_profile_picture 
    = f.label :remove_profile_picture, 'Delete your Profile Picture' 

    = f.label :profile_picture, 'Replace your Profile Picture' 
    - else 
    = f.label :profile_picture, 'Add your Profile Picture' 
    = f.file_field :profile_picture 

    %p 
    = f.submit 'Save' 
    or 
    = link_to 'cancel', @user 

プラットフォーム:

  • レール3.1.0
  • carrierwave 0.5.7
  • Herokuの杉スタック

答えて

0

まだ全くわからない。ここ

コードですなぜこれは動作しますが、私は私のモデル

def profile_picture_file_name 
    read_attribute :profile_picture_file 
end 

にメソッドを追加し、

f.object.profile_picture.file.basename 

するのではなく、私の見解では、そのメソッドを使用して、すべてが今、幸せです。

Displaying a Carrierwave filename in the viewに感謝します。

関連する問題