As I''m sure you''re aware, Javascript can go basically
anywhere, and there is
no set place to put said JS. If the script is to work and be available for
every page, either put it in your layout, or if it''s complicated (or
there
are multiple layouts), then yeah, put it in the public/javascripts folder.
If it''s simple, small functions and you want to keep the source clean,
then
you can do something like this:
in layout:
<head>
...
<script ...>
<%= yield :javascript %>
</script>
...
</head>
and in your rhtml:
<% content_for(:javascript) do %>
put javascript stuff here
<% end %>
Hope that helps.
Jason
On 1/18/07, Lee <lee_longmore-/E1597aS9LT10XsdtD+oqA@public.gmane.org>
wrote:>
>
> I want to add some simple JS code to my application that registers an
> ''onclick'' event for a form field and calls a function to
change various
> DOM elements.
>
> Where is the best place to put this?
>
> In the layout for the view? In application.js?
>
> Thanks.
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---