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

  • Home
  • SEARCH
  • 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 8918083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:39:40+00:00 2026-06-15T05:39:40+00:00

I have a rails application which will upload image with the name as same

  • 0

I have a rails application which will upload image with the name as same as the book id to assets/books_icon when the user creates a book.

upload_icon(params[:book][:image_upload])

# upload_image when create/update book
    def upload_icon(uploaded_io)
       photo_directory = "app/assets/images/"

       # only when user upload the iphoto
       if uploaded_io.present?

         # upload to the exact location with category_id
         extension = File.extname(uploaded_io.original_filename)
         photo_location = 'books_image/'+ @book.id.to_s + extension

         # open in binary mode
         photo_full_location = photo_directory + photo_location
         File.open(photo_full_location, 'wb') do |file|
           file.write(uploaded_io.read)
         end

         # only have to state which is the directory, 
         # image_tag will use assets piepline which will add 'assets/images/' as prefix in src 
         @book.update_attribute(:image_url, photo_location)
       end
     end

It works in the development mode.Then, I deployed the rails application with passenger on mac Apache2 server with mysql as the database and I changed config.assets.compile = true in the development configuration file.

In the production mode, I can create the new book and I can upload the image to assets/books_icon. However, the file path for the image which I just upload will not update.

For example, I create a new book with id 2, and there is 2.jpg in assets/books_icon. But the rails application will told me http://localhost/assets/images/books_icon/2.jpg is missing.

However, when I restart the apache server, I can view the picture at http://localhost/assets/images/books_icon/2.jpg

Is there any solutions to solve this type of caching problem??

  • 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-06-15T05:39:42+00:00Added an answer on June 15, 2026 at 5:39 am

    In this context, an uploaded image isn’t really considered an “asset” — think of it as data that you happen to be storing somewhere else. (An image asset might be a logo, or background image, etc.). Rails’ asset pipeline does some pretty tricky stuff in order to resolve a simple file path to an actual resource (e.g. image) when it’s an asset.

    By default, Rails makes the app/public folder the document root, and thus a place that you could upload images to — perhaps in a subdirectory called “upload/img” in which case you could reference it with the path /upload/img/mybook.jpg.

    This approach tends to be fragile, however because the image is really directly associated with data in your database, but located on the filesystem of a server. It starts falling apart when you move from development to stagings or production servers.

    One approach I would not recommend is to upload the image and store it as a blob type in your database. Another I would recommend is to have another “central” server that you can upload images to that acts as an extension to your database. Many people use Amazon AWS “S3” service for this kind of thing. Take a look at the CarrierWave gem which does an excellent job of making all of this really easy, flexible, and powerful.

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

Sidebar

Related Questions

I am experimenting with a design for a Rails application which will have most
I am writing ruby on rails application, which will have 2 different users types
I have a ruby on rails 3.0 application which will need a database containing
I'm looking at building a Rails application which will have some pretty large tables
I have a model in my rails application which is class Person < ActiveRecord::Base
I have a Rails 3.2.2 application which is a simple company intranet, however although
In my rails application, I have a controller called demo which is stored at
I have created a blog application using Ruby on Rails which includes the ability
I have a SharePoint server. I am building an rails application which can interact
I have a Rails application with a public REST API which authenticates API clients

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.