All, I have a RXML template which renders partial RXML templates within it. A snippet is below. The "xml" variable is the parent template''s Builder variable. It is passed into the partial under the name "parent_xml". Why can''t I use :locals => {.... :xml => xml ....} in my call to render the partial? It seems like if I do use :xml => xml, it doesn''t work, and I am forced to pass into a local variable with a name other than "xml", for example, "parent_xml". Thanks, Wes ========== snippet of main template =============== xml.tbody do objects.each do |obj| xml.tr do render(:partial => ''common/list_buttons_display'', :layout => false, :locals => {:parent_xml => xml, :buttons => buttons, :obj => obj}) if buttons_first ========== snippet of RXML partial =============== columns.each do |col_array| attr_name = col_array[0] column_display_name = col_array[1] value = eval("obj.#{attr_name}") column_contents = (column_display_name == ''Fax Number'' ? number_to_phone(value, {:area_code => true}) : value) parent_xml.td(column_contents, :id => "#{obj.id}_#{attr_name}") end -- 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 -~----------~----~----~----~------~----~------~--~---
rxml templates automatically instantiate a xml builder object under the "xml" variable, so if you are passing it from the parent, you are getting it overriden by the one created at the beginning of the template. what i usually do is pass it under another name (parent_xml is perfect) and then do something like xml = parent_xml unless parent_xml.nil? this way you can consistently use the "xml" variable as your root element throughout all the templates/partials regards, javier Wes Gamble wrote:> All, > > I have a RXML template which renders partial RXML templates within it. > > A snippet is below. The "xml" variable is the parent template''s Builder > variable. It is passed into the partial under the name "parent_xml". > > Why can''t I use :locals => {.... :xml => xml ....} in my call to render > the partial? It seems like if I do use :xml => xml, it doesn''t work, > and I am forced to pass into a local variable with a name other than > "xml", for example, "parent_xml". > > Thanks, > Wes > > ========== snippet of main template ===============> > xml.tbody do > objects.each do |obj| > xml.tr do > render(:partial => ''common/list_buttons_display'', > :layout => false, > :locals => {:parent_xml => xml, > :buttons => buttons, > :obj => obj}) if buttons_first > > ========== snippet of RXML partial ===============> > columns.each do |col_array| > attr_name = col_array[0] > column_display_name = col_array[1] > value = eval("obj.#{attr_name}") > column_contents = (column_display_name == ''Fax Number'' ? > number_to_phone(value, {:area_code => true}) : > value) > parent_xml.td(column_contents, :id => "#{obj.id}_#{attr_name}") > 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 -~----------~----~----~----~------~----~------~--~---
Javier, Thanks. I suspected that xml was the "default variable". Wes -- 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 -~----------~----~----~----~------~----~------~--~---
Maybe Matching Threads
- [PATCH 1/1] hivexml: Base64-encode non-printable data
- Overriding AR read/write_attribute - Overridden write_attribute Is Never Called
- HABTM with finder_sql problem (Rails bug?)
- "include" versus "extend" - what's the difference
- Major issues with ActiveRecord callbacks in BackgroundRb r324