Rails - activate javascript

Is there any chance to display a precompiled javascript file? A simple file has no problems with:

def iframe_communication
  render file: "/app/assets/javascripts/iframe_communication_module.js"
end

I tried assets_pathor included it in javascript_include_tagthe view, but failed.

For clarification, I do not want to add a script to my view. I am trying to display a javascript file for external access (tagging <script>from other domains).

Refresh

  • render file: "..." shows file as expected but not compiled version
  • assets_path "/app/assets/javascripts/iframe_communication_module.js"returns "/app/assets/javascripts/iframe_communication_module.js", not the path to the compiled resource
  • javascript_include_tag loads the script as expected (no rendering)

The Rails 4 resource pipeline compiles everything into a single file, is there any chance of getting one file from it?
Or is this the best way to compile it manually?

2
this: assets_path , . :

asset_path "application.js" # => /application.js  
asset_path "application", type: :javascript # => /javascripts/application.js
+4
1

:

.

//= stub iframe_communication_module

apps/assets/javascript/application.js.

,

config.assets.precompile += %w( iframe_communication_module.js )

to config\application.rb

,

redirect_to ActionController::Base.helpers.javascript_path("iframe_communication_module")

.

+1

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


All Articles