Stylesheet_link_tag creating absolute links instead of relative ones

I installed facebooker to tunnel my Ruby on Rails application.

The problem is that I would like to test locally. That is, I do not want to start the tunnel every time I want to see my changes.

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

I do not need this functionality; I do not see changes in CSS or JavaScript without having to run a tunnel. I want the links to be relative, not absolute. So stylesheet_link_tag should produce /stylesheets/appName.css?1234567890 .

Does anyone know why he is doing this and how to fix it?

Thanks in advance.

+4
source share
1 answer

AssetTagHelper uses your asset_host URL. I'm not sure if facebooker installs it for you (I don't know much about facebooker), but you can reset in your view no problem:

Before your stylesheet_link_tab just redefines 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!

+13
source

Source: https://habr.com/ru/post/1310328/


All Articles