Hi guys I''m trying to use rjs to access a tag property. For example, <div id="foo" trogdor_id="5"> How do I get the value of trogdor_id with rjs? Thanks! -- 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 -~----------~----~----~----~------~----~------~--~---
This should work: page[:foo][:trogdor_id] -Bill Totally Girl wrote:> Hi guys > > I''m trying to use rjs to access a tag property. For example, > > <div id="foo" trogdor_id="5"> > > How do I get the value of trogdor_id with rjs? 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 -~----------~----~----~----~------~----~------~--~---
Thanks so much for the reply William! I''m getting an error when converting to string. This is my code below: html: <div id="theDivName" trogdor="5">blah blah</div> rjs: testing_id = page[:theDivName][:trogdor] page.replace_html("replacement_div", :partial => "some_partial", :locals => {:passing_testing_id => testing_id }) _some_partial: This is the testing_id: <%= testing_id %>> This should work: > > page[:foo][:trogdor_id] > > -Bill-- 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 -~----------~----~----~----~------~----~------~--~---
That won''t work because rjs is just converted to javascript then sent to the browser, so your variable would never have that id in it. You will need to pass the trogdor id in a link or as a hidden form variable. -Bill Totally Girl wrote:> Thanks so much for the reply William! > > I''m getting an error when converting to string. This is my code below: > > html: > <div id="theDivName" trogdor="5">blah blah</div> > > rjs: > testing_id = page[:theDivName][:trogdor] > > page.replace_html("replacement_div", > :partial => "some_partial", > :locals => {:passing_testing_id => testing_id > }) > _some_partial: > > This is the testing_id: <%= testing_id %> > > > >> This should work: >> >> page[:foo][:trogdor_id] >> >> -Bill >> > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks again bill. Would you have an example of how to do that? William Pratt wrote:> That won''t work because rjs is just converted to javascript then sent to > the browser, so your variable would never have that id in it. You will > need to pass the trogdor id in a link or as a hidden form variable. > > -Bill-- 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 -~----------~----~----~----~------~----~------~--~---
Sure, if the user is clicking on a link to trigger the action then this works: <%= link_to_remote ''Click Me'', :url => {:controller => ''somecontroller'', :action => ''someaction'', :trogdor_id => ''a_trogdor_id''} %> Now you can access it as params[:trogdor_id]. You could also just use :id instead of trogdor_id unless it''s being used as something else. I assume this would be done in a loop setting trogdor_id on each iteration. If this is part of a form then: <%= hidden_field_tag :trogdor_id, ''a_trogdor_id'' -%> Hope this helps. -Bill Totally Girl wrote:> Thanks again bill. Would you have an example of how to do that? > > William Pratt wrote: > >> That won''t work because rjs is just converted to javascript then sent to >> the browser, so your variable would never have that id in it. You will >> need to pass the trogdor id in a link or as a hidden form variable. >> >> -Bill >> > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---