I want to include this, for example:
jQuery(document).ready(function($) {
$('#my-modal').modal(options)
});
In one specific place in a rails app. In my case the file is called views/modals/mymodal.html.erb. There and only there.
I can't figure out how to do that without getting it on all pages as would happen if I put it in assets.
These are some useful tricks
your.js
for your javascript your.js
on specific your layout //= require_tree .
on application.js
your.js
to asset percompile on config/application.rb
: config.assets.precompile += %w( your.js )
put your js script with javascript tag on mymodal.html.erb
put your js script into layout/yourlayout.html.erb
and use if.. else..
logic.
example :
<% if current_page?(yourspecific_path) %> <script language="text/javascript"> your javascript here .. </script> <% end %>
Read more here about current_page?
Or use request.fullpath
to get current full path
example :
<% if request.fullpath == yourspecific_path %> <script language="text/javascript"> your javascript here .. </script> <% end %>
Read more here about request.fullpath
Also you can combine #1 and #3 if you want script put into file .js
cheers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With