Michael Slater | 16 May 21:09
Gravatar

Cleanest syntax for form partial?


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@...
To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Craig Demyanovich | 16 May 21:21
Picon
Gravatar

Re: Cleanest syntax for form partial?


On Fri, May 16, 2008 at 3:13 PM, Michael Slater <ms@...> 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@...
To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Nathan Esquenazi | 18 May 01:38
Gravatar

Re: Cleanest syntax for form partial?


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@...
To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Ix Quic | 18 May 03:37
Picon

Re: Cleanest syntax for form partial?


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@...
To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Ryan Bigg (Radar | 19 May 04:05
Picon
Gravatar

Re: Cleanest syntax for form partial?

<% form_for ... do | <at> 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
-~----------~----~----~----~------~----~------~--~---

Rick DeNatale | 19 May 13:15
Picon

Re: Cleanest syntax for form partial?


On Sun, May 18, 2008 at 10:05 PM, Ryan Bigg (Radar)
<radarlistener@...> 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@...
To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Ryan Bigg (Radar | 19 May 13:21
Picon
Gravatar

Re: Cleanest syntax for form partial?

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 | <at> 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
-~----------~----~----~----~------~----~------~--~---


Gmane