Re: [la-ruby] Looking for Rails/Javascript pattern ...

From: Randy W.
Sent on: Saturday, September 19, 2009 3:44 AM

I would also like to know where to best keep the needed
Javascript code.

Put your javascript functions in /public/javascripts/application.js

Then place the following in the <head> section of your layout, such as�� /app/views/layouts/your_layout_for_your_controller.html.erb... or /app/views/layouts/application.html.erb, (with the latter, it will be loaded on each page, even if not needed/used, although, the browser should cache the javascript file between pages unless that was turned off in Firefox's about:config)

�� <%= javascript_include_tag 'application' %>

You can also use:
�� <%= javascript_include_tag :defaults %>
which will load all of the default javascript files in the /public/javascripts directory.�� Needed if you are using the prototype/scriptaculous AJAX stuff.

If you only need some functions for one view, put the following into the view's erb file:

�� <% content_for(:head) do -%>������������������������������
�� <%= javascript_include_tag 'application' %>
�� <% end -%>������������������������������������������������������������������

you can also create any file you like, and simply replace 'application' with the name of your new file sans ".js"


People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy