File_field vs. file_field_tag


#1

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


#2

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


#3

On 15.1.2006, at 18.42, Peter M. 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


#4

Thanks. That is more clear than the docs.

Peter


#5

On 15.1.2006, at 19.19, Peter M. 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