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%> how do i add the prototype stuff correctly? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Feb 22, 11:26 am, Adam Akhtar <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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> > how do i add the prototype stuff correctly? > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sun, Feb 22, 2009 at 4:30 AM, Frederick Cheung < frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > On Feb 22, 11:26 am, Adam Akhtar <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > 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 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 -~----------~----~----~----~------~----~------~--~---
On Sun, Feb 22, 2009 at 3:26 AM, Adam Akhtar <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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".> <% if items.empty?> > #the following is not the correct way > $(''no-items-msg'').showWhy would you do this with JS?? Just put the message here. Then users with or without JS enabled (including spiders and web service clients) will get the intended view.> <% else >FWIW, -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thank you all for your input. Thank you hassan for answering some of my doubts abou this methodology. Basically this is the result of my lack of knowledge. The rows in this table represent tasks in a todolist. Theres a delete option for each task via ajax and the deleted row is taken out via $().remove_html calls. when all the rows are taken out though i need to show that message. This is true in reverse. When there are initially no tasks this message wiill be shown, when a user adds via ajax a task, the row is inserted via .insert_html. Hence the message needs to be hidden. I thought it best to do it via a .hide or .show call. Sorry this is a very quick explanation as my girlfriend is currently screaming at me that i spend too much time on the pc and i fear for my life. If anyone has a design pattern \ best practice about how to handle tables and messages indicating there are no records plus ajax calls. please tell. ill be back tomorow -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Adam Akhtar 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".Does the program know this when the page renders, or will the message change during the time your user looks at the page?> 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%>Things in <% erb %> tags happen only when the page renders, so you could just put that <div id=''no-items-msg''> itself inside the <% if %> blocks. No Javascript. If the message must change at runtime, then you will need an Ajax call, such as remote_function, to call an action on your server. It uses ''render :update'' to call show() or hide() on that div. -- Phlip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi thanks for the reply. What i did in the end was to type the "no records" message into the view directly so that non javascript enabled users could still see it. I then created some javascript code to handle the situations above. Thanks everyone for yoru help. it really helped me out -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---