Close
Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

LABS
javascript_include_tag in Rails

Want to avoid feeling like a chump and spending countless hours troubleshooting a crazily-stupid-simple problem?

When you enter a .js in your javascripts directory and include it using a javascript_include_tag, take the <script> tags off the front and back.

You probably knew that already. Why didn’t you tell me sooner?

Comments
  1. >Want to avoid feeling like a chump and spending countless hours troubleshooting a crazily-stupid-simple problem?

    Why, yes! Yes I do!

    >When you enter a .js in your javascripts directory and include it using a javascriptincludetag, take the

    Oh, okay.

    >You probably knew that already. Why didn't you tell me sooner?

    I didn't knowit already! You have to believe me!

  2. Jonah Dempcy says:

    Here’s another tip:

    the javascript_include_tag also allows you to include multiple scripts at once, separated by commas.

    I’ve seen people use it over and over like this:

    javascript_include_tag(“script1″)
    javascript_include_tag(“script2″)
    javascript_include_tag(“script3″)

    Instead, you can just do this:

    javascript_include_tag(“script1″, “script2″, “script3″)

    you can also include :defaults which can be configured (but by default is Prototype/Scriptaculous) and you can include :all which will nab everything in the public/javascripts folder.

Post a Comment

Your Information (Name required. Email address will not be displayed with comment.)

* Copy This Password *

* Type Or Paste Password Here *