I have a simple show/hide function for a div as follows : <%= link_to_function "Show|Hide", visual_effect(:toggle_slide, :images, :duration => 1, :queue => ''end'') %> I''d like to just display Hide, then when the link is clicked perform the toggle_slide and then change the link text to ''Show'' (and back when clicked again). I''d like to do something like : <%= link_to_function "Hide", update_page{|page| page.visual_effect(:toggle_slide, :images, :duration => 1, :queue => ''end'') if page.select(''toggle_images'') == ''Hide'' page.select(''toggle_images'').replace_html(:text => ''Show'') else page.select(''toggle_images'').replace_html(:text => ''Hide'') end }, { :id => ''toggle_images''} %> However you can''t use Ruby within the block like this (as far as I can tell). I could use an Ajax call to a partial to do the replace but this seems overkill. Does anybody have a solution for this example that doesn''t involve custom JS or an Ajax call ? -- 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 -~----------~----~----~----~------~----~------~--~---
Terry Donaghe
2006-Sep-26 17:46 UTC
Re: Conditional Protoypte updates - Is there a simple answer ?
I think this code is just screaming for an RJS template. Change your link_to_function to a link_to_remote and name your action after your RJS template name. Don''t define a method for this in your controller and Rails will magically find your RJS template. All of your page.* code should go into the RJS template just fine. Read about RJS stuff here: http://rubynoob.com/articles/2006/05/13/simple-rails-rjs-tutorial And here''s a list to lots of stuff: http://www.rubyinside.com/16-rjs-resources-and-tutorials-for-rails-programmers-5.html Hope that helps! On 9/26/06, robl <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > I have a simple show/hide function for a div as follows : > > <%= link_to_function "Show|Hide", > visual_effect(:toggle_slide, :images, :duration => 1, :queue => > ''end'') %> > > I''d like to just display Hide, then when the link is clicked perform the > toggle_slide and then change the link text to ''Show'' (and back when > clicked again). > > I''d like to do something like : > > <%= link_to_function "Hide", update_page{|page| > page.visual_effect(:toggle_slide, :images, :duration => 1, :queue => > ''end'') > if page.select(''toggle_images'') == ''Hide'' > page.select(''toggle_images'').replace_html(:text => ''Show'') > else > page.select(''toggle_images'').replace_html(:text => ''Hide'') > end > }, > { :id => ''toggle_images''} %> > > However you can''t use Ruby within the block like this (as far as I can > tell). I could use an Ajax call to a partial to do the replace but this > seems overkill. > > Does anybody have a solution for this example that doesn''t involve > custom JS or an Ajax call ? > > -- > Posted via http://www.ruby-forum.com/. > > > >-- Terry (TAD) Donaghe http://www.rubynoob.com http://www.tadspot.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 -~----------~----~----~----~------~----~------~--~---
Vishnu Gopal
2006-Sep-26 18:16 UTC
Re: Conditional Protoypte updates - Is there a simple answer ?
You might want to take a look at the UJS plugin. http://www.ujs4rails.com/ This seems like the kind of thing you want. It''s all ruby, with no javascript anywhere. And can be DRY too if used well. Have a <a href="#" id="toggle">Hide</a>, and your RJS-ish code inside an apply_behavior. Vish On 9/26/06, Terry Donaghe <terry.donaghe-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I think this code is just screaming for an RJS template. > > Change your link_to_function to a link_to_remote and name your action > after your RJS template name. Don''t define a method for this in your > controller and Rails will magically find your RJS template. All of your > page.* code should go into the RJS template just fine. > > Read about RJS stuff here: > > http://rubynoob.com/articles/2006/05/13/simple-rails-rjs-tutorial > > And here''s a list to lots of stuff: > > > http://www.rubyinside.com/16-rjs-resources-and-tutorials-for-rails-programmers-5.html > > Hope that helps! > > > > On 9/26/06, robl <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > > > > > I have a simple show/hide function for a div as follows : > > > > <%= link_to_function "Show|Hide", > > visual_effect(:toggle_slide, :images, :duration => 1, :queue => > > ''end'') %> > > > > I''d like to just display Hide, then when the link is clicked perform the > > toggle_slide and then change the link text to ''Show'' (and back when > > clicked again). > > > > I''d like to do something like : > > > > <%= link_to_function "Hide", update_page{|page| > > page.visual_effect(:toggle_slide, :images, :duration => 1, :queue => > > ''end'') > > if page.select(''toggle_images'') == ''Hide'' > > page.select(''toggle_images'').replace_html(:text => ''Show'') > > else > > page.select(''toggle_images'').replace_html(:text => ''Hide'') > > end > > }, > > { :id => ''toggle_images''} %> > > > > However you can''t use Ruby within the block like this (as far as I can > > tell). I could use an Ajax call to a partial to do the replace but this > > > > seems overkill. > > > > Does anybody have a solution for this example that doesn''t involve > > custom JS or an Ajax call ? > > > > -- > > Posted via http://www.ruby-forum.com/. > > > > Terry (TAD) Donaghe > > http://www.rubynoob.com > > http://www.tadspot.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 -~----------~----~----~----~------~----~------~--~---
But that means I need to do a remote call to a server to replace some innerHTML for a DOM element for an already known value - not very efficient really ... -- 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 -~----------~----~----~----~------~----~------~--~---