jimjohnlists-/E1597aS9LQAvxtiuMwx3w@public.gmane.org
2007-Mar-09 04:28 UTC
How do you pass html objects from the view to the helper classes?
I would like to pass the title to the helper class and manipulate it. I have in the view <div id="select02_div" title="show"> <h4>test</h4> </div> In the helper, I have def hide_and_reset(div) update_page do |page| if page[div].title == ''show'' page[div].hide page[div].title = ''hide'' else page[div].title = ''show'' page[div].show end end end --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Michael Wang
2007-Mar-09 04:36 UTC
Re: How do you pass html objects from the view to the helper classes?
jimjohnlists-/E1597aS9LQAvxtiuMwx3w@public.gmane.org wrote:> I would like to pass the title to the helper class and manipulate it. > > I have in the view > > <div id="select02_div" title="show"> > <h4>test</h4> > </div> > > In the helper, I have > > def hide_and_reset(div) > update_page do |page| > if page[div].title == ''show'' > page[div].hide > page[div].title = ''hide'' > else > page[div].title = ''show'' > page[div].show > end > end > endYou can''t. The helper has already been run on the server side before the page is sent to the client. At that point the browser has no idea that there was a helper function in the original .rhtml file. To hide or show DIVs on the browser you need to write some JavaScript or if the hide/show conditions depend on information on the server you can use Ajax. -- Michael Wang --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
jimjohnlists-/E1597aS9LQAvxtiuMwx3w@public.gmane.org
2007-Mar-09 04:55 UTC
Re: How do you pass html objects from the view to the helper classes?
Thanks. I can call the helper with this line in my code in the view. <%= link_to_function image_tag("graphics/ select04.gif", :alt=>''Programming'', :size=>''100x20'', :border=>0), hide_and_reset(:select02_div, :select01_div) %> The helper class seems to update the view. I can hide <div id="select02_div" title="show">...</div>, but I don''t know how to show it or know how to check to see if it is hidden using the helper class. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Michael Wang
2007-Mar-09 05:13 UTC
Re: How do you pass html objects from the view to the helper classes?
jimjohnlists-/E1597aS9LQAvxtiuMwx3w@public.gmane.org wrote:> > Thanks. I can call the helper with this line in my code in the view. > > <%= link_to_function image_tag("graphics/ > select04.gif", :alt=>''Programming'', :size=>''100x20'', :border=>0), > hide_and_reset(:select02_div, :select01_div) %> > > The helper class seems to update the view. I can hide <div > id="select02_div" title="show">...</div>, but I don''t know how to show > it or know how to check to see if it is hidden using the helper class.The hide_and_reset() in the link_to_function looks like a JavaScript function, not a Rails helper method. -- Michael Wang --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
eden li
2007-Mar-09 05:21 UTC
Re: How do you pass html objects from the view to the helper classes?
In this case, your helper function is actually returning a chunk of javascript that is called when you click on the image. Ruby''s not changing the page -- javascript is. update_page is generating this javascript based on the block you gave it. Unfortunately, in this case, the javascript you''re getting is not what you expect. If you add <%= hide_and_reset(:select02_div, :select01_div) %> you can see what''s being created on your behalf. update_page() is good in a lot of simple cases, but if you really need flexibility, you''ll have to dip down into native javascript. For this case something like the following will work def hide_and_reset(div) update_page do |page| el = page[div] page << <-"end" if (#{el}.title == "show") { #{el}.hide(); #{el}.title "hide"; } else { #{el}.show(); #{el}.title = "show"; } end end end On Mar 9, 12:55 pm, "jimjohnli...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org" <jimjohnli...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> Thanks. I can call the helper with this line in my code in the view. > > <%= link_to_function image_tag("graphics/ > select04.gif", :alt=>''Programming'', :size=>''100x20'', :border=>0), > hide_and_reset(:select02_div, :select01_div) %> > > The helper class seems to update the view. I can hide <div > id="select02_div" title="show">...</div>, but I don''t know how to show > it or know how to check to see if it is hidden using the helper class.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
jimjohnlists-/E1597aS9LQAvxtiuMwx3w@public.gmane.org
2007-Mar-09 05:45 UTC
Re: How do you pass html objects from the view to the helper classes?
Thanks guys. I see your point in not wasting server calls just for simple stuff that should be done on the client only in plain javascript. I use the Oreilly book Ruby on Rails Up and Running. It''s too basic. I was wondering if you guys have any good books or tutorials you recommend that provides more advance use of ruby on rails, especially with AJAX. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
eden li
2007-Mar-09 06:05 UTC
Re: How do you pass html objects from the view to the helper classes?
For most things you don''t actually need ajax -- instead you can usually get away with plain javascript. The ORA javascript and dhtml books are good starts: * http://www.oreilly.com/catalog/jscript4/ * http://www.oreilly.com/catalog/dhtmlref/ On Mar 9, 1:45 pm, "jimjohnli...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org" <jimjohnli...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> Thanks guys. I see your point in not wasting server calls just for > simple stuff that should be done on the client only in plain > javascript. I use the Oreilly book Ruby on Rails Up and Running. It''s > too basic. I was wondering if you guys have any good books or > tutorials you recommend that provides more advance use of ruby on > rails, especially with AJAX.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---