Reputation: 15259
I am using Ruby on Rails 4.1.1 and on my local machine I have the following image:
# Directory: MyApp/app/assets/images/
logo.png
I upload MyApp using the Capistrano gem and all seems to work as expected. However when I try to access my website through the browser at the following URLs
1) http://www.myapp.org/logo.png
2) http://www.myapp.org/assets/logo.png
3) http://www.myapp.org/images/logo.png
4) http://www.myapp.org/assets/images/logo.png
then I get an error page:
The page you were looking for doesn't exist.
You may have mistyped the address or the page may have moved.
In the log file I get:
1) ActionController::RoutingError (No route matches [GET] "/logo.png"):
2) ActionController::RoutingError (No route matches [GET] "/assets/logo.png"):
3) ActionController::RoutingError (No route matches [GET] "/images/logo.png"):
4) ActionController::RoutingError (No route matches [GET] "/assets/images/logo.png"):
actionpack (4.1.1) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (4.1.1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.1.1) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.1.1) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.1.1) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.1.1) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.1.1) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.1.1) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.1.1) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.1.1) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.1.1) lib/rails/engine.rb:514:in `call'
railties (4.1.1) lib/rails/application.rb:144:in `call'
railties (4.1.1) lib/rails/railtie.rb:194:in `public_send'
railties (4.1.1) lib/rails/railtie.rb:194:in `method_missing'
/usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.45/lib/phusion_passenger/rack/thread_handler_extension.rb:74:in `process_request'
/usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.45/lib/phusion_passenger/request_handler/thread_handler.rb:141:in `accept_and_process_next_request'
/usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.45/lib/phusion_passenger/request_handler/thread_handler.rb:109:in `main_loop'
/usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.45/lib/phusion_passenger/request_handler.rb:448:in `block (3 levels) in start_threads'
What is the problem and how can I solve it?
Upvotes: 0
Views: 488
Reputation: 1599
All assets that are compiled in Production have a fingerprint ID appended to the file name. Therefore, in production, logo.png does not technically exist anymore. What should exist now is logo-SOME_FINGERPRINT_ID.png. See more info here:
Also, if you wish to serve just the static image, you will need to put it in the images dir of the public folder. You will then need to tell Apache or Nginx to serve static assets from that location.
EDIT: To link to an image in your Asset Pipeline -
link_to(LINK_TEXT_OR_IMAGE_TAG_HELPER, image_path(IMAGE_NAME))
Upvotes: 1