10

What the how the, where the..

<%= javascript_include_tag :defaults %>

this little evil line is pulling in 3 additional JavaScript that I could essentially give less then a damn about. In fact I would like to use that to redefine some defaults on a per page basis. However I can't seem to figure out where those defaults are defined.

Ive been on google and bing looking for answers but I yield none. I keep coming up with a document or 3 that explain using it, but not how I can use it.

2 Answers 2

11

Use the Rails API documentation for this.

If the application is not using the asset pipeline, to include the default JavaScript expansion pass :defaults as source. By default, :defaults loads jQuery, and that can be overridden in config/application.rb:

config.action_view.javascript_expansions[:defaults] = %w(foo.js bar.js)

When using :defaults, if an application.js file exists in public/javascripts it will be included as well at the end.

Sign up to request clarification or add additional context in comments.

2 Comments

I've got jquery_ujs.js, jquery.js, application.js all auto loading. I assume based off that one little line. So am I to assume that that's like the default of the default (if that makes sense, like when nothing is configured or whatever.) I guess my end game logic when it comes to finding this out is, are these something I can turn off change, or would i be better off hardcoding javascript to my html
or better yet can I define my own :custom or :blah definition? Cause some pages I will require more then that defaults on where as others I only need the defaults
0

For rails 6 may use javascript_pack_tag 'application', 'data-turbolinks-track': 'reload'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.