Rails 3.1.rc1 Image Tags - ruby-on-rails-3.1

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.

Related

404 Error in Magento extension when deployed in production

This one is puzzling me for 2 days now. I've found a solution for a 404 in admin, but it is not the same that is happening here. I have exactly the same version of Magento in my local copy and production server: 1.7.0.2. The extension works great in local. I packaged it using Magento Connect and installed in production the same way. All files are there. It shows in the menu and in Configuration section, but when I click the menu to go to the report, I get the beloved 404. I loged out and in, flushed cache zillion times (including deleting the files manually) but nothing changed.This are the URLs in both envs:
(Dev)http://localhost/magentos/index.php/salestaxes/adminhtml_salestaxes/index/key/c4b8ecb58fa2062f696cacfd340/
(Prod)https://www.myserver.com/index.php/salestaxes/adminhtml_salestaxes/index/key/332e617e74a92a39a40cf5d3/
As you can see is exactly the same. I don't know wahy then I'm getting the error. Can somebody point what can I do to solve this? DO I need to check any setting? What can cause this?
This is a var_dump that I get in the router _validateControllerClassName() method:
string(115) "/home_path/public_html/app/code/community/Surpassweb/SalesTaxes/controllers/Adminhtml/SalestaxesController.php"
string(100) "/home_path/public_html/app/code/community/Surpassweb/SalesTaxes/controllers/IndexController.php"
This is the output of Alam's 404 module:
Controller Name
Controller Name: adminhtml_salestaxes
The controller name adminhtml_salestaxes matches the following controller file, but this file does not exist.
home_path/public_html/app/code/community/MyCompany/SalesTaxes/controllers/Adminhtml/SalestaxesController.php
The file is there and has 755 permissions.
This is the first line in may controller:
class MyCompany_SalesTaxes_Adminhtml_SalesTaxesController extends Mage_Adminhtml_Controller_Action {
Thanks for your time.
Are you absolutely sure the file is there? Named the same? With the same character capitalization? And that you're not in a production setup with multiple frontend webservers?
If you'll indulge me — copy the path of the controller from the Better 404 page to your computer's clipboard. Then type
$ ls -l [PASTE]
into your terminal window. My bet if the file won't be there. Also try
$ls -l app/code/community/Surpassweb/SalesTaxes/controllers/Adminhtml/
to see what files are there.
Looking at the information you provided, Magento is looking for a file named
app/code/community/MyCompany/SalesTaxes/controllers/Adminhtml/SalestaxesController.php
I don't know what your actual file is named, but looking at the class name
MyCompany_SalesTaxes_Adminhtml_SalesTaxesController
leads me to believe it might be incorrectly named SalesTaxesControlle.php. Notice the T in sales taxes is capitalized, vs the lowercase t Magento is looking for.
For some reason magento isn't registering the route to your app.
Either apache doesn't know to let magento handle it or magento doesn't know what to do with it.
Check your htaccess files and virtual host configs for the two environments.
Right off the bat I can see they're not exactly the same. One is http and one is https.
Those are probably two different virtual host configs and could be slightly different.
Next I would make sure the config xml for your module is included in magento/app/etc/modules/ folder. Make sure the module is enabled. There should be a line for that in your modules config xml file.
If you deployed it to the local vs community folder, check the magento/app/etc/local.xml and make sure disable_local_modules is set to no.
Good luck. Troubleshooting in live is always fun.

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.

Paperclip routing error in Rails 3.1: only applies to new images

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.

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.

Resources