Paperclip routing error in Rails 3.1: only applies to new images - ruby-on-rails-3.1

I am having essentially the same problem as this questioner: Paperclip routing error. The server gives a 404 for a static file (which is present!), so Rails gets called and then there is a routing error.
My Rails 3.1 app uses paperclip to attach files, but when serving files in production the following error is logged by Rails:
Started GET "/system/images/9/thumb/Large%20image.jpg?1320149338" for [...]
ActionController::RoutingError (No route matches [GET] "/system/images/9/thumb/Large%20image.jpg"):
Corresponding to an NGINX access log entry:
"GET /system/images/9/thumb/Large%20image.jpg HTTP/1.1" 404 728 "-" [...]
So, a few observations:
This didn't happen in the past, and past images with almost identical URLs still work, e.g.: /system/images/1/thumb/StoneSkimming%20Demyhb%20Art%203.jpg is served correctly.
The image files were uploaded, and converted by ImageMagick, correctly - I have verified all the expected files are in the right place, and are valid JPEGs with the right image in them.
Permissions for the files are all as expected, and match the files that still work.
The entries in the database for the relevant model look correct.
Adding/removing the query string, or putting the URL directly into the browser gives the same result as the embedded <img> tag: the image is not found.
Can anyone point me in the right direction here? I am having trouble working out how to test/debug this because the error is not universal across the app.
I am using Capistrano to deploy, so /public/system is a symlink to the shared directory. My instinct is that this is not the problem though, as older images in the same location work just fine.

I managed to solve problems with paperclip when deploying with capistrano to production by adding to capistrano deploy config:
namespace :deploy do
desc "build missing paperclip styles"
task :build_missing_paperclip_styles, :roles => :app do
run "cd #{current_path}; RAILS_ENV=production bundle exec rake paperclip:refresh:missing_styles"
end
end
after("deploy:update_code", "deploy:build_missing_paperclip_styles")
Probably there is better solution.

Related

Rails 4 - ActiveAdmin - Redactor - Heroku -- has no method 'redactor' console error

I've been trying to tackle this all morning. Locally, this setup works just fine. I am not using the redactor-rails gem because this is a rails 4 app and it doesn't support it. I have moved the redactor.css and redactor.js calls from the active_admin initializer file to be required in my actice_admin.js.coffee and active_admin.css files because on Heroku, it could not find the path. Now, when firing up the page that should be displaying redactor, I get has no method 'redactor' in the console.
I'm at a loss. I've read up on precompiling assets and the how the pipeline works, but it doesn't seem like I'm doing anything out of the ordinary here.
So how can I deploy to Heroku without this error?
Ok, so I seemed to have disregarded an important task. After thinking about precompilation a bit more I remembered I had been told to run
RAILS_ENV=production bundle exec rake assets:precompile
before. After running that again, it precompiled the active_admin.css and active_admin.js.coffee files which had the new require's in it. Viola!
Hope this helps someone else in the future.

How can I set up a download link to a pdf in rails 3.2?

I'm new with Rails and I'm having trouble understanding why the following error occurs. I have a page where I've linked a pdf file and some images for download.
In the view:
link_to( image_tag('image.png'),:controller=>'home',:action=>'download', :file_name => 'image.pdf') %>
In the controller:
def download
send_file "#{RAILS_ROOT}/assets/pdf/#{params[:file_name]}", :type=>"text/pdf"
end
When I try to download the file in the development environment I get the following error:
No route matches [GET] "/assets"
I've tried changing the path to the file and searching on google and SO. I imagine this must be a relatively simple fix and probably has to do with the asset pipeline but if someone could point me in the right direction, I'd be very happy.
Hey there I ran into this issue myself and the solution for me (rails 2.0.2) was to put the pdf file into the public directory of your application and make a direct link www.yoursite.com/my.pdf this will execute the download right away.
Why is this?
well once you deploy your app the rake assets:precompile will be ran and therefor the assets will appear in your public directory.
You can also do this local by running
$:. rake assets:precompile RAILS_ENV="development"
Although I would not advice commiting these files.

Rails 3 asset routing issues in production

I currently have my assets in the jquery.rest.js and jquery-ui-1.8.11.custom.min.js files in my app/assets directory, yet i keep getting the following errors in my production logs.
Started GET "/assets/jquery.rest-f1490ffc30dcefe21715ae360de2bead.js" for 24.141.74.123 at 2011-12-20 18:40:50 -0500
Served asset /jquery.rest-f1490ffc30dcefe21715ae360de2bead.js - 404 Not Found (3ms)
ActionController::RoutingError (No route matches [GET] "/assets/jquery.rest-f1490ffc30dcefe21715ae360de2bead.js"):
Started GET "/assets/jquery-ui-1.8.11.custom.min-707e06de7fe351e6e77e419988c20fd6.js" for 24.141.74.123 at 2011-12-20 18:40:50 -0500
Served asset /jquery-ui-1.8.11.custom.min-707e06de7fe351e6e77e419988c20fd6.js - 404 Not Found (3ms)
ActionController::RoutingError (No route matches [GET] "/assets/jquery-ui-1.8.11.custom.min-707e06de7fe351e6e77e419988c20fd6.js"):
My app works in development, i dont know why the long string is appended at the end of of the name of javascript files ie -707e06de7fe351e6e77e419988c20fd6 for jquery-ui-1.8.11.custom.min.js in production
The string is called a fingerprint. Rails adds these in production mode to allow the assets to be cached on the client-side to improve performance. This is covered in the Rails asset pipeline guide
One of the by-products of adopting this strategy is that you must pre-compile your files for production. This is done via a special task built in to Rails, and is usually run by Capistrano during deployment (you need to set this up - details are in the guide).
Also, when you have js and css files that are not in a manifest (the default application.css and application.js) they don't get precompiled unless you add them into a config variable.
Can you edit your question to include how you link to the files and also let me know if you are using the manifests and if you are precompiling or not?
Same issue I have.
The comment under the selected answer did not for me, but the following works for me:
- vim config/application.rb
# Comment this to avoid `ActionController::RoutingError (No route matches [GET] "/assets/jquery-ui-1.8.16.custom.min-1116bf6f7eb1469bb3c60f6af13199ac.js");`
# config.assets.debug = true
Thanks.

Rails 3.1.1 getting broken image on image assets

I'm missing something with the asset pipeline functionality. Things work fine in development and I move to run in production environment and all hell breaks loose!
So I have an image in app/assets/images named "logo.png"
I precompile (RAILS_ENV=production rake assets:precompile) and I can verify that in public/assets there now exists both a logo.png and logo-5fa60e416f495e562c56a5087fe696dc.png
I then run in production rails s thin -e production
But I get a broken image
GET http://localhost:3000/assets/logo-5fa60e416f495e562c56a5087fe696dc.png 404 (Not Found)
What is going on?
I also notice that when I switch to production I also starting getting javascript errors like "JQuery is not found" for jquery tools EVEN THOUGH no problems in development AND I specify in my application.js that jquery should be loaded first before any other javascript files.
The solution is simple (finding it was not).
Simply update your config/production.rb to reflect the following:
config.serve_static_assets = true
Though this is set to false by default, only when you set it to true will you be able to properly run your rails 3.1.x application locally (via webbrick or in my case thin) in the production environment. You'll probably want to set it back to false before you deploy to your actual production server.

Rails 3.1.rc1 Image Tags

I'm trying to implement Rails 3.1 in my project, but none of my image_tags are working.
I really need nested has_many :through, which is why I choose to upgrade.
I know that images/javascripts/stylesheets should now go into app/assets/
However due to complications with my theme, I would like to keep them in public/
How would I go about doing so?
The image_tag, javascript_include_tag, and stylesheet_tag are looking only in the assets directory.
Console Output Example
Started GET "/assets/icons/small/white/Alarm%20Bell.png" for 127.0.0.1 at 2011-05-27 11:04:48 -0400
Served asset /icons/small/white/Alarm%20Bell.png - 404 Not Found (0.00488s) (pid 1656)
That file is really located in "public/images/icons/small/white/Alarm Bell.png"
Thanks
Got it.
In application.rb, at the bottom, set the asset pipeline to false.

Resources