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

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.

Related

mounting several apps with camping

I'm testing how to mount several apps in camping, and I am following these instructions. I have this structure:
more/apps/
pm.rb
qm.rb
Both apps just return the index view with some text. When I startup the server, the index shows the pm's index when the address is http://localhost:3301/.
If I try http://localhost:3301/pm, I get this error:
Camping Problem!
/pm not found
Same error for qm. Am I missing something?
This does not work anymore. camping now only accepts a single file. You can still mount multiple apps, but you need a single file that requires them:
# in apps.rb
require 'pm'
require 'qm'
And then you can run:
camping apps.rb
I'm not sure how to do this yet but in the issues on camping github they mentioned using a config.ru like you would for any Rack app.
I hope this helps.

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.

codeigniter display error: Unable to locate the model you have specified:

I use latest version of CI, that is 2.1.2.
I upload my demo application in the following location http://www.domainname.com/myfolder/index.php
If i try to open home page, welcome controller is opened correctly. However if I try to open http://www.domainname.com/myfolder/index.php/controllername/functionname page, I get the following error message:
An Error Was Encountered
Unable to locate the model you have specified: backofficeusersmodel
In my config file, I have the following settings:
$config[‘base_url’] = ‘http://www.domainname/myfolder/’;
$config[‘index_page’] = ‘index.php’;
I also tried and
$config[‘base_url’] = ‘http://www.domainname.com/myfolder/application/’;
$config[‘index_page’] = ‘index.php’;
without any success.
However, the model is uploaded and its name is backOfficeUsersModel, not as stated in the error message all lover case.
I would like to mention that I use myModel (uploaded in application/core), and that same strange thing was happening when I upload same application under some free hosting, just there the error was that mymodel could not be located.
I upload same application on different hosting company and there it worked. Also, same application work normally on my localhost.
Anyone had similar experience?
Model files should be in application/models folder and should be named in lower case like backofficeusersmodel. Probably there is a deficiency in these requirements.

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.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