Lee.Longmore-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2007-May-15 06:23 UTC
Best Practice: render :partial
I have been using "render :partial" throughout my application but have
just realised that I am perhaps not using it in the way intended.
I am for example referencing instance variables directly within my
partial and not passing them as either an :object or a local variable
(:locals). On reflection, this seems bad practice.
For example, I have a partial called
"property_name" ("_property_name.rhtml") that renders a text
input
field:
<% if @property.class == PropertyCollection %>
<p><label for="property_name">What would you like to
call this
collection?</label><br/>
<% else %>
<p><label for="property_name">What would you like to
call this?</
label><br/>
<% end %>
<%= text_field :property, :name %></p>
I wrote this as a partial because I use it within both create and edit
forms, and I wanted to avoid duplication.
As you can see I am currently referring to @property.
Any advice on how I might refactor the above would be much
appreciated.
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
-~----------~----~----~----~------~----~------~--~---