I want to access the file /public/images/dog.jpg in the Rails project. Is there some URL route that would access it?
I tried public/images/dog.jpg and images/dog.jpg, but it didn't work.
images/dog.jpg is correct.
However I would use the image_path URL route, e.g. image_path('dog.jpg').
See http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets
Related
From the docs it seems like you just save yourself from typing in the assets folder part of the image url when using this method against the vanilla url helper? What is the usefulness of this?
When you use image_url helper then rails will map the full qualified url based on the asset_host configuration. So this method gives you the freedom of just passing the name of the image as an argument and it does the rest.
Check this for more information.
http://api.rubyonrails.org/classes/ActionView/Helpers/AssetUrlHelper.html
I am trying to create routes within an app that I am working on like the following example:
http://www.example.com/entrepreneur.com/article/251468
My hope is to basically load an external page into an iframe by adding our domain to the URL. It needs to be without storing the external url in a database because I need every website accessable in this way. How can I do this?
You need a route with a wildcard like this:
get 'url/*args', to: 'your_controller#your_action'
See http://guides.rubyonrails.org/routing.html#route-globbing-and-wildcard-segments
I would suggest you namespace the route under some keyword to catch this wildcard route explicitly (hence url in the above).
You may need to tweak the route to allow periods to prevent them from becoming the format. I forget if that's true for these or not.
I would like to display a pdf in an iframe in one of my Rails projects. My current code is <iframe src="tmp/data.pdf"></iframe>, but when I go to this page, I get the error: "No route matches [GET] /Users//development//tmp/data.pdf".
data.pdf is in this location, so I think I'm doing something wrong with my routes file, and maybe I have to route the file to a path appropriately. I've tried playing around with a few things, but haven't had much luck so far. Can anyone provide any help?
Rails only exposes the contents of the "public" subfolder to the webbrowser so no code/configuration can be downloaded by any user...
Try putting the file there and it should work.
UPDATE 1
Also you need to note, that the "public" part does not have to be included in the URL. So in your case the url would be just "/data.pdf".
According to the Paperclip S3 Docs one can specify the :url option in the config which has four possible values. There are comments related to this options that say:
The fourth option for the S3 url is :asset_host, which uses Rails' built-in asset_host settings.
To get the full url from a paperclip'd object, use the image_path helper; this is what image_tag uses to generate the url for an img tag.
These two comments seem in conflict with each other (to me). If Paperclip can use the asset_host settings, it seems almost necessary that it would generate the full url (since the asset_host only specifies the start (host) of that url)
But it then goes on to say you need to use a helper to get the full url??
The reason I ask this is because I want full urls generated for image url serialization (ie if we're returning json with image_urls, we want those served from our CDN).
Right now I've created a helper module that extends extend ::Sprockets::Helpers::RailsHelper to manually generate full urls any time an image_url is being serialized, but it's manual (and someone could possibly forget to do it in the future)
Any thoughts?
i am using symfony 1.4.11; use_helper('Url').
On using link_to('new',course/course/type/new),
the url it show is ../backend_dev/backend_dev/Course/course/type/new
instead of
../backend_dev/Course/course/type/new.
Same issue exist for form_tag also.
Edit
Above issue was solved.By setting no_script_name: true at config and clearing cache.
But image_tag(),use_stylesheet() and use_javascript() gives path as for example
use_javascript('jquery-1.6.1.min.js')
==>../web/backend_dev/js/jquery-1.6.1.min.js
instead of
use_javascript('jquery-1.6.1.min.js') ==>../web/js/jquery-1.6.1.min.js
Any help appreciated.
Hard to say without your full routing.yml but the one thing i see is that your internal_uri should be expressed as an abs url with a query string like:
link_to('new','/Course/course?type=new');
Note the forward slash at the beginning. Also the module name should be the real module name, not the routed one so if the maodule is /apps/backend/modules/Course then the module in the internal URI should be Course not course same with the action name.
If the route is named then you should use one of the following:
link_to('new','#routename?type=new');
OR
link_to('new','routename', array('type'=>'new'));