On Jan 6, 2011, at 3:35 AM, Colin Law wrote:

On 5 January 2011 22:56, Rob Biedenharn <[email protected]> wrote:
On Jan 5, 2011, at 5:21 PM, Colin Law wrote:

On 5 January 2011 21:45, Brian Ablaza <[email protected]> wrote:

I have an app that manages tapes. Each tape has a number (separate from
the record ID in MySQL).

When a tape is added, the number field can be filled in. But when the
record is subsequently edited, the number should not be editable.
[...
Rather than check the action, I'd suggest checking whether the object was
new.

<% if f.object.new_record? %>
 <%= f.text_field :number %>
<% else %>
 <%= f.object.number %>
<% end %>

I don't think I approve of doing it this way.  This is putting too
much intelligence into the view.  The view is saying 'I know that if
the object is a new record then I should display this field'.  Instead
I suggest one should set a flag in the controller action, then the
view is just saying 'I know that if this flag is set I should show
this field'.  Call the flag show_id or similar and the view is just
obeying orders, not making decisions.

Colin

Well, the half-way position would be to move just the :number attribute out of the partial and put the text_field into the 'new' view and the simple display into the 'edit' view avoiding any explicit test. My point was that there's no reason to completely abandon the idea that the fields of the model that are common to the 'new' and 'edit' actions reside in a partial.

-Rob

Rob Biedenharn          
[email protected]     http://AgileConsultingLLC.com/
[email protected]               http://GaslightSoftware.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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to