Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6610877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:53:48+00:00 2026-05-25T19:53:48+00:00

Trying to add carrier wave based image uploading to my user model. This works

  • 0

Trying to add carrier wave based image uploading to my user model. This works locally in development. On heroku, the image is uploaded to my s3 bucket, but never displayed. In the console, it looks like no image was uploaded.

If the image is making it to s3, why isn’t it being associated properly?

Here’s the code:

# 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

Platform:

  • rails 3.1.0
  • carrierwave 0.5.7
  • heroku cedar stack
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:53:49+00:00Added an answer on May 25, 2026 at 7:53 pm

    Still not entirely sure why this works, but I added a method to my model

    def profile_picture_file_name
      read_attribute :profile_picture_file
    end
    

    and use that method in my view instead of

    f.object.profile_picture.file.basename
    

    And everything is happy now.

    Thanks to Displaying a Carrierwave filename in the view.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying add a tab to my web page that looks like this: Using
Trying to add text to QGraphicsView: Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this);
Trying to add objects to a ArrayDeque at random intervals. This is what I
I'm trying to add an index to my models, but keep getting this error.
i'm new to django and im trying add a user using django admin page.
Trying to add a second line to this so it shows the Name of
Trying to add my event handler to ComponentDispatcher.ThreadPreprocessMessage event like this: using System; using
Trying to add an onclick handler to my tabs, and can't seem to get
trying to add an ExpiresDefault ExpiresByType to content on my website so that way
Trying to add a 'box' to a form at design time, I looked up

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.