Forum: Ruby on Rails Best Practice: render :partial

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
(Guest)
on 2007-05-15 10:25
(Received via mailing list)
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.
This topic is locked and can not be replied to.