Forum: Ruby on Rails ActionView::Helpers::FormHelper instance methods should take

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.
B780ee0ee1480454a85df58536702f63?d=identicon&s=25 Alder Green (Guest)
on 2006-04-08 17:53
(Received via mailing list)
Hi

ActionView::Helpers::FormHelper methods (e.g. #text_field,
#check_box...) take object_name as an argument. From this argument
they infer a name that is supposed to contains the reference to the
relevant object.

I can't see why the FormHelper methods were designed that way.
Compared to simply passing them a reference, the current way seems too
complicated and an invitation to problems or at least limitations.

For example, if you call text_field("post", "title"), the method would
look for a @post instance variable. Imagine you were using a local
variable for storing the relevant object, instead of an instance
variable. If text_field took a reference, you would just call it with
text_field(post, :title). However, since it takes a string an infers a
reference name, you now have to change your assigned names or at least
create new aliases to your existing names.

To sum up, I can't see any advantages to the object_name approach, I
don't understand why FormHelper was initially designed that way, so I
think it should be changed so as to be more convenient and flexible.
What do you think?

Regards,
Alder
A28088e0bbbdecd6663d554f7be1273f?d=identicon&s=25 Wiebe Cazemier (Guest)
on 2006-04-08 17:56
(Received via mailing list)
On Saturday 08 April 2006 17:50, Alder Green wrote:

>
> think it should be changed so as to be more convenient and flexible.
> What do you think?
>
> Regards,
> Alder

It provides some useful additions. Like mass assigning with
.attributes=, and
the use of validations without worrying about anything. Look at my post
on the
list I made 2 minutes before you did, which explains a bit about
validations.

In situations where you encounter limitations, use the text_field_tag
method
instead.
Ec5a599777854c540fd102ef4691fe10?d=identicon&s=25 Rimantas Liubertas (Guest)
on 2006-04-08 18:02
(Received via mailing list)
<...>
> For example, if you call text_field("post", "title"), the method would
> look for a @post instance variable. Imagine you were using a local
> variable for storing the relevant object, instead of an instance
> variable. If text_field took a reference, you would just call it with
> text_field(post, :title). However, since it takes a string an infers a
> reference name, you now have to change your assigned names or at least
> create new aliases to your existing names.
<...>

... or simply use text_field_tag instead of text_field.


> To sum up, I can't see any advantages to the object_name approach, I
> don't understand why FormHelper was initially designed that way, so I
> think it should be changed so as to be more convenient and flexible.
> What do you think?

Nothing should be changed, When you want to work with model's
attributes you use text_field (which makes updates as simple as
update_attributes params[:model]) ,
when you want something 'flexible' you use text_field_tag.


Regards,
Rimantas
--
http://rimantas.com/
This topic is locked and can not be replied to.