On 5 January 2011 22:56, Rob Biedenharn <Rob@agileconsultingllc.com> wrote:
> On Jan 5, 2011, at 5:21 PM, Colin Law wrote:
>
>> On 5 January 2011 21:45, Brian Ablaza <lists@ruby-forum.com> 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
--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment