开发者

stylesheet_link_tag producing absolute links instead of relative

开发者 https://www.devze.com 2022-12-30 18:51 出处:网络
I set up facebooker to tunnel my Ruby on Rails application. The issue is that I would like to test locally. That is, I don\'t want to have to start a tunnel every time I want to see my changes.

I set up facebooker to tunnel my Ruby on Rails application.

The issue is that I would like to test locally. That is, I don't want to have to start a tunnel every time I want to see my changes.

Right now, when I start the application using ruby script/server (not calling rake facebooker:tunnel:background_start beforehand), links created by helpers (e.g., stylesheet_link_tag, javascript_include_tag, image_tag) are prepended with my tunnlr address: http://web1.tunnlr.com:myPort/. (For example, a CSS link looks like this in the page source: http://web1.tunnlr.com:myPort//stylesheets/appName.css?1234567890.)

I don't want that functionality; I can't see my CSS or JavaScript changes without having to start the tunnel first. I want the links to be relative, not absolute. So, stylesheet_link_tag should produce /stylesheets/appName.css?1234567890.

Does anyone know why it's doing that in the first place and how to fix it?

Thanks in advance.开发者_如何学运维


The AssetTagHelper uses your asset_host URL. I am not sure whether facebooker is setting it for you (I don't know much about facebooker), but you can reset it in your view no problem:

Before your stylesheet_link_tab just override the host URL:

ActionController::Base.asset_host = "localhost:3000"
# or
ActionController::Base.asset_host = ""

So using ERB it might look like this:

<% ActionController::Base.asset_host = "" %>
<%= stylesheet_link_tag "stylesheet.css" %>

Walabing!

0

精彩评论

暂无评论...
验证码 换一张
取 消