How to use <script> in Rails 7
How do I display a that holds a url with the .js I want to display. For example, <script src="https://greatsite.com/widgets/awesomescript.js">. I am very new to Rails, been learning for only 3 months.
You can have a controller respond to the JS format.
respond_to do |format|
format.js
end
And then render a action.js.erb
file
Is the action.js.erb
file a partial of a view? Sorry, it's the first time I have seen a js.erb it has only been html.erb to this point.
Nope, partials start with an underscore. The js.erb
extension is the format + the renderer. So this example is a response for the js
format and rendered using erb
.