Forum: Ruby on Rails file_field vs. file_field_tag

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.
Eea3feaacbe44706164289d068d94828?d=identicon&s=25 Peter Michaux (Guest)
on 2006-01-15 17:44
(Received via mailing list)
Hi,

The documentation doesn't make it clear why both file_field and
file_field_tag are both useful. What is the reason for having two
instead of just one of these?

Thanks,
Peter
82476266af9d460415d8f1fc16bb54ed?d=identicon&s=25 Jarkko Laine (jarkko)
on 2006-01-15 17:48
(Received via mailing list)
On 15.1.2006, at 18.42, Peter Michaux wrote:

> Hi,
>
> The documentation doesn't make it clear why both file_field and
> file_field_tag are both useful. What is the reason for having two
> instead of just one of these?

The former is meant for (normal) situations where you have an object
+method pair at hand. The latter is a more low-level method with
which you have to do more handiwork. It's useful in cases where you
don't have a matching object and method for the field (a search form
comes to mind).

If you take a closer look at the api, you'll notice that similar
methods exist for all form field types, like text_field and
text_field_tag.

//jarkko
Eea3feaacbe44706164289d068d94828?d=identicon&s=25 Peter Michaux (Guest)
on 2006-01-15 18:22
(Received via mailing list)
It looks like file_field is the one that is more low-level with more
options.
82476266af9d460415d8f1fc16bb54ed?d=identicon&s=25 Jarkko Laine (jarkko)
on 2006-01-15 18:32
(Received via mailing list)
On 15.1.2006, at 19.19, Peter Michaux wrote:

> It looks like file_field is the one that is more low-level with
> more options.

I won't go into debating which is more low-level, but file_field
assumes that you give it an object and a method and bakes you an
input field from those, with id and name attributes set
automatically. You don't have to specify anything else.

file_field_tag, however, doesn't know anything about objects.

So in effect, the two following would be roughly equivalent:

<%= file_field "person", "photo" %>

<%= file_field_tag "person[photo]", :id => "person_photo" %>

//jarkko
Eea3feaacbe44706164289d068d94828?d=identicon&s=25 Peter Michaux (Guest)
on 2006-01-15 18:36
(Received via mailing list)
Thanks. That is more clear than the docs.

Peter
This topic is locked and can not be replied to.