The full resource URL in the Rails.js.erb file

I have a bookmarklet that can be downloaded on any website.

It works as follows:

  • downloads http://my.example.com/assets/bookmarklet.js
  • includes http://my.example.com/assets/bookmarklet.css

The css file is added to dom via bookmarklet.js , so it needs to know where it is.

My code is as follows:

 // assets/javascripts/bookmarklet.js.erb var config = { stylesheetUrl: '<%= asset_path("bookmarklet.css", :only_path => false) %>' } 

But no matter what I'm trying to do, it looks like

 var config = { stylesheetUrl: '/assets/bookmarklet.css' } 

I need asset_path to return the full url. But asset_url does not exist, and I cannot find a variant of asset_path that will add the current domain.

Any solution?

+6
source share
1 answer

You need to set an explicit resource host for each environment. For instance:

 # development.rb config.action_controller.asset_host = "http://localhost:3000" 
+8
source

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


All Articles