As you might guess from the title - this is going to be a quick and simple post. Today I wish to cover nothing more then two basic Rails tags that you can include in any of your views.
The first of these is the javascript_include_tag - which simply attaches a javascript file to your .rhtml document. Its syntax is simple and should not be easily confused:
<%= javascript_include_tag "myjsfile" %>
The statement above will produce the HTML markup required to attach the file myjsfile.js from the /www/javascripts/ directory. If you want to add more than one file at a time do something like so:
<%= javascript_include_tag "jsFile1", "jsFile2", "jsFile3" %>
Each file name is seperated by a comma. If you name your javascript file something different than jsFile.js (extension .js) then give the full name such as jsFile.javascript (to attach the file /www/javascripts/jsFile.javascripts).
Next up is another simple tag- and I wont spend much time on it. The syntax is the same although it directs its links to the directory /www/stylesheets/. To attach one or more stylesheets use something like so:
<%= stylesheet_link_tag "somestyle" %>
Pretty simple - but I suppose we all need to be reminded of the simple stuff from time to time!
