Switching/Linking to another external stylesheet in a .js file using Ruby on Rails
Posted
by Jake
on Stack Overflow
See other posts from Stack Overflow
or by Jake
Published on 2010-06-03T20:01:38Z
Indexed on
2010/06/03
20:04 UTC
Read the original article
Hit count: 302
Im learning JQuery from a Sitepoint Book but Im trying to apply all the lessons to a Rails App. In one lesson, we are taught how to switch to a different stylesheet if the browser window is resized beyond a certain point. Here's the javascript code:
if ($('body').width() > 900) { $('<link rel="stylesheet" href="wide.css" type="text/css" />')
.appendTo('head'); } else { $('link[href=wide.css]').remove(); }
Rails doesn't seem to want to link to the new stylesheet using 'link rel'. I've tried using the Rails helper: <%= stylesheet_link_tag 'base', :media => 'screen' %>
but that doesn't work in a .js file.
How do I link to an external stylesheet in a .js file using Ruby? Can I use Ruby on Rails code in a .js file?
Thanks.
© Stack Overflow or respective owner