Relative stylesheet and javascript links.

50 views
Skip to first unread message

Jake

unread,
Mar 22, 2012, 2:35:49 PM3/22/12
to Serve Users
Perhaps this isn't a Serve question, I really don't know. I'm new to
the world of Rails. Anyway. I have a site that works great using the
Serve server but when exported the CSS and JavaScript links contain
'/' at the beginning. The client won't be running these files from the
web root so I need a way to remove that '/' prefix so the HTML will
treat it as relative. I'm using stylesheet_link_tag and
javascript_include_tag to generate the HTML. Is there a config or
something I set to have these generate relative links?

Thanks,

Jake

Jess Brown

unread,
Mar 22, 2012, 4:30:28 PM3/22/12
to serve...@googlegroups.com
Hi Jake,

You could do something like this (if using erb):

<% @base_url = "/" if ENV['RACK_ENV'] == "development" %>
<base href="<%= @base_url %>" />
<link href="stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css" />


Jess




--
Jess Brown
Brown Web Design

Jake

unread,
Mar 22, 2012, 6:27:54 PM3/22/12
to Serve Users
Oh, that looks like a good workaround. Thanks for the advice.

Jake
> @BrownWebDesign <http://twitter.com/brownwebdesign>
>
> Let's chat!  Schedule a phone call <http://brownwebdesign.com/book>

Chris Lee

unread,
Jul 31, 2013, 10:20:22 PM7/31/13
to serve...@googlegroups.com, avera...@gmail.com
Can you do the same with haml?

Jess Brown

unread,
Jul 31, 2013, 11:01:19 PM7/31/13
to serve...@googlegroups.com, avera...@gmail.com
I wouldn't see why not.  You'd just need to convert the erb tags to haml...something like this:

- @base_url = "/" if ENV['RACK_ENV'] == "development"
%base{:href => @base_url}
%link{:href => "stylesheets/screen.css", :media => "screen, projection", :rel => "stylesheet", :type => "text/css"}


Jess Brown
Brown Web Design

Let's chat!  Schedule a phone call
--
--
Serve Users Group
Mailing List: http://groups.google.com/group/serve-users/
Project: http://github.com/jlong/serve/
 
---
You received this message because you are subscribed to the Google Groups "Serve Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to serve-users...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages