Shifra Pride RaffelShifra Pride Raffel
javascript_include_tag in Rails
edit Posted by Shifra Pride Raffel on Thursday December 13, 2007 at 05:22PM

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. Stephen Pride Raffel Stephen Pride Raffel on December 14, 2007 at 05:27PM

    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 Jonah Dempcy on June 06, 2008 at 09:30PM

    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.