File_field vs. file_field_tag

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

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

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

Thanks. That is more clear than the docs.

Peter

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs