When I''m in a form block and am including a partial, I use: <%= render :partial => ''form'', :locals => {:f => f} %> Is there a cleaner way to write this? Something new in Rails 2 maybe? Michael --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Fri, May 16, 2008 at 3:13 PM, Michael Slater <ms-04BUtanlfE1BDgjK7y7TUQ@public.gmane.org> wrote:> <%= render :partial => ''form'', :locals => {:f => f} %> > > Is there a cleaner way to write this? Something new in Rails 2 maybe?I don''t know of one off hand. What''s dirty about that style? Craig --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Check this out: http://www.railsjedi.com/posts/22-Better-Partials-Plugin-for-Ruby-on-Rails Turns this: <%= render :partial => ''form'', :locals => {:f => f} %> into: <%= partial "form", :f => f %> -- 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 -~----------~----~----~----~------~----~------~--~---
In Rails 2.1: <% form_for ... do |f| %> <%= render :partial => f %> which renders _form.html.erb (*) where the local variable is called form. *) or _foobar_form.html.erb if you use a custom FoobarFormBuilder http://dev.rubyonrails.org/changeset/8646 Michael Slater wrote:> When I''m in a form block and am including a partial, I use: > > <%= render :partial => ''form'', :locals => {:f => f} %> > > Is there a cleaner way to write this? Something new in Rails 2 maybe? > > Michael--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
<% form_for ... do |@f| %> <%= render :partial => "form" %> <% end %> Even cleaner! Passing in your form object as an instance variable gives you the added bonus of having it available in any partial you render after defining it. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Sun, May 18, 2008 at 10:05 PM, Ryan Bigg (Radar) <radarlistener-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> <% form_for ... do |@f| %> > <%= render :partial => "form" %> > <% end %> > > Even cleaner! Passing in your form object as an instance variable gives you > the added bonus of having it available in any partial you render after > defining it.Cleanliness is in the eye of the beholder. In any case, beware that Ruby 1.9 disallows using instance variables as block parameters, so if you''re forward thinking this might be a technique to avoid. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.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 -~----------~----~----~----~------~----~------~--~---
Bugger! I had a niggling thought at the back of my mind as I wrote that post that it was the case, but chose to ignore it. Oh well, render :partial => "form", :f => f looks like the cleanest way for now, unless you don''t mind not being Ruby 1.9 compatible, but it will come to bite you in the ass later on. On Mon, May 19, 2008 at 8:45 PM, Rick DeNatale <rick.denatale-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On Sun, May 18, 2008 at 10:05 PM, Ryan Bigg (Radar) > <radarlistener-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > <% form_for ... do |@f| %> > > <%= render :partial => "form" %> > > <% end %> > > > > Even cleaner! Passing in your form object as an instance variable gives > you > > the added bonus of having it available in any partial you render after > > defining it. > > Cleanliness is in the eye of the beholder. > > In any case, beware that Ruby 1.9 disallows using instance variables > as block parameters, so if you''re forward thinking this might be a > technique to avoid. > > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/ > > > >-- Appreciated my help? Reccommend me on Working With Rails http://workingwithrails.com/person/11030-ryan-bigg --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---