Rails Route to Static File in Public
I am using open-flash-chart’s and want to use a route for the swf file rather than a direct url/path written into my views. The reason for this is that in deployment the app is not at the root directory but at www.wetware.co.nz/something , which makes the public folder www.wetware.co.nz/something/public.
If you directly link to /open-flash-chart.swf, it will work on development but not on production because there is a difference in the routing.
You can easily make a route to fix this
map.graph_swf ‘/open-flash-chart.swf’, :controller => “not_a_controller”, :path => ‘/open-flash-chart.swf’
Related Posts
Posted on June 16, 2009 at 10:27 pm by Jordan Carter · Permalink
In: Uncategorized · Tagged with: open-flash-charts, rails routes, routes
In: Uncategorized · Tagged with: open-flash-charts, rails routes, routes
on January 8, 2011 at 2:16 pm
Permalink
In production just set:
config.serve_static_assets = true
and you don’t need any of the above mapping.
on April 2, 2011 at 7:25 pm
Permalink
The proper way to fix this for a robust production environment is to hand responsibility for static requests off to your web server, for example Apache. Then your application server, for example mongrel, or better yet, unicorn will only have to handle the dynamic requests they are designed for and the web server will handle the static requests it is designed for. If you are using Apache, then these lines in your /etc/httpd/conf/httpd.conf (Fedora) will tell Apache not to proxy forward the static content. The “!” is the NOT operator in this context. It would be better to place flash files in their own directory and not proxy anything in that directory, as is the case for stylesheets, javascripts and images below.
ProxyPass /open-flash-chart.swf !
ProxyPass /stylesheets/ !
ProxyPass /javascripts/ !
ProxyPass /images/ !
Cheers,
Mark