On Sun, Feb 22, 2009 at 4:30 AM, Frederick Cheung <
[email protected]> wrote:

>
>
>
> On Feb 22, 11:26 am, Adam Akhtar <[email protected]>
> wrote:
> > Im incorporating ajax / javascript stuff for the first time in my
> > project and im a bit confused by all various methods available, rjs,
> > prototype, javascript etc so please excuse me if this is an obvious
> > question.
> >
> > Whilst looping though an array of model objects in my view I want to be
> > able to show or hide a div that contains the message "Your list is
> > empty".
> >
> > so something like this
> >
> > <% if items.empty?>
> > #the following is not the correct way
> > $('no-items-msg').show
> > <% else >
> > $('no-items-msg').hide
> > <% items.each do |item|%>
> > render :partial => "item_rows"......
> > <%end%>
>
> First off in javascript the () for function calls is mandatory - $('no-
> items-msg').show just evaluates to a function object, you need $('no-
> items-msg').show() to actually call it. secondly your javascript needs
> to be inside <script> tags (there's a rails helper that will assist
> with this, can't remember what it's called but it has javascript in
> the name.
>

Fred, I believe you're referring to the javascript_tag Rails helper.


>
> Fred
> >
> > how do i add the prototype stuff correctly?
>

Adam, you'll need to add the following inside your HTML <head> tag:

<%= javascript_include_tag :defaults %>

Good luck,

-Conrad

--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to