Methods of custom form builder work if the form is in a view, but doesn''t work if the form is in a partial. My rediced code example looks like this: # -- Builder ----------------------------------------- class CustomBuilder < ActionView::Helpers::FormBuilder def drawTextField return ''<input type="text" />'' end end # -- View -------------------------------------------- <% form_for :thisUser, :url => {:action => :testForm}, :builder => CustomBuilder do |form| %> <%= render(:partial => ''testForm''}) rescue nil %> <% end %> # -- Partial ----------------------------------------- <%= form.drawTextField %> If I simply move the drawTextField line into the view it works fine. Using the partial, the page renders everything but the partial (no field). No errors in log. I poked around a fair bit, but have no more ideas to try. -- gw (www.railsdev.ws) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Greg Willits
2007-Nov-17 09:11 UTC
Re: Custom form builder methods won''t render in partial
On Nov 16, 2007, at 3:59 PM, Greg Willits wrote:> Methods of custom form builder work if the form is in a view, but > doesn''t work if the form is in a partial.Nevermind. I''m an idiot. Obviously the |form| object has to be passed into the partial. Duh. -- gw (www.railsdev.ws) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Nov-17 13:31 UTC
Re: Custom form builder methods won''t render in partial
Greg, I don''t mean to muddy the waters on this question, but I believe that you need to have a <%= render :partial => "form", :locals => { :form => form } %> type statement to pass the ''form'' value from the calling view to the partial. Kathy On Nov 17, 3:11 am, Greg Willits <li...-0Bv1hcaDFPRk211Z5VL+QA@public.gmane.org> wrote:> On Nov 16, 2007, at 3:59 PM, Greg Willits wrote: > > > Methods of custom form builder work if the form is in a view, but > > doesn''t work if the form is in a partial. > > Nevermind. I''m an idiot. Obviously the |form| object has to be passed > into the partial. Duh. > > -- gw (www.railsdev.ws)--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
William Pratt
2007-Nov-17 18:14 UTC
Re: Custom form builder methods won''t render in partial
I don''t think so. Your formbuilder methods will be available to partials just as if they were any view. I use a custom formbuilder in almost all my forms and I use a lot of partials due to heavy reliance on rjs. Greg, I didn''t see the original stacktrace you sent. Can you paste it back in? -Bill On Nov 17, 2007, at 5:31 AM, KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> > Greg, > I don''t mean to muddy the waters on this question, but I believe that > you need to have a > > <%= render :partial => "form", :locals => { :form => form } %> > > type statement to pass the ''form'' value from the calling view to the > partial. > Kathy > > On Nov 17, 3:11 am, Greg Willits <li...-0Bv1hcaDFPRk211Z5VL+QA@public.gmane.org> wrote: >> On Nov 16, 2007, at 3:59 PM, Greg Willits wrote: >> >>> Methods of custom form builder work if the form is in a view, but >>> doesn''t work if the form is in a partial. >> >> Nevermind. I''m an idiot. Obviously the |form| object has to be passed >> into the partial. Duh. >> >> -- gw (www.railsdev.ws) > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Greg Willits
2007-Nov-17 18:39 UTC
Re: Custom form builder methods won''t render in partial
@Kathy> <%= render :partial => "form", :locals => { :form => form } %>Yeah, that''s what I did to solve it. @Bill> Your formbuilder methods will be available to > partials just as if they were any view"Hmm, well, there''s a definite correlation to it working or not if I pass the the form builder into the partial.> I didn''t see the original stacktrace you sent. Can you > paste it back in?Below is the original reduced code I tested. The update now is that if I add a :locals to the render command to pass the form variable thru, it works. -- gw (www.railsdev.ws) On Nov 16, 2007, at 3:59 PM, Greg Willits wrote:> Methods of custom form builder work if the form is in a view, but > doesn''t work if the form is in a partial. > > My rediced code example looks like this: > > # -- Builder ----------------------------------------- > class CustomBuilder < ActionView::Helpers::FormBuilder > > def drawTextField > return ''<input type="text" />'' > end > end > > # -- View -------------------------------------------- > <% form_for :thisUser, > :url => {:action => :testForm}, > :builder => CustomBuilder do |form| %> > > <%= render(:partial => ''testForm''}) rescue nil %> > > <% end %> > > # -- Partial ----------------------------------------- > <%= form.drawTextField %> > > > If I simply move the drawTextField line into the view it works fine. > Using the partial, the page renders everything but the partial (no > field). No errors in log. > > I poked around a fair bit, but have no more ideas to try.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Why did you think "form" would be in scope in the partial? The way I always handle this is as follows: <% form_for :foo do |f| %> <%= render :partial => ''bar'', :locals => {:f => f} %> <% end %> Then in the partial, using any member of the yielded object "f" is valid. Does this help? On Nov 16, 2007, at 3:59 PM, Greg Willits wrote:> > Methods of custom form builder work if the form is in a view, but > doesn''t work if the form is in a partial. > > My rediced code example looks like this: > > # -- Builder ----------------------------------------- > class CustomBuilder < ActionView::Helpers::FormBuilder > > def drawTextField > return ''<input type="text" />'' > end > end > > # -- View -------------------------------------------- > <% form_for :thisUser, > :url => {:action => :testForm}, > :builder => CustomBuilder do |form| %> > > <%= render(:partial => ''testForm''}) rescue nil %> > > <% end %> > > # -- Partial ----------------------------------------- > <%= form.drawTextField %> > > > If I simply move the drawTextField line into the view it works fine. > Using the partial, the page renders everything but the partial (no > field). No errors in log. > > I poked around a fair bit, but have no more ideas to try. > > -- gw (www.railsdev.ws) > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---