Forum: Ruby on Rails View helpers and nested attributes

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.
ruben (Guest)
on 2005-12-01 18:42
(Received via mailing list)
Hello all,

I have a model with two entities (document and asset) and a 1:1
relationship defined between them (every model has an asset).

I want to generate a rthml view that generates a hash for document
attributes and a nested hash for asset attributes (for example
{:document =>{:name=>XXX :asset => {date =>XXX}})

According to the Pragmatic Programmers book (page 355), the input fields
for this should be something like

<input type="text" name="document[name]" />
<input type="text" name="document[asset][name]" />

The question is: how can i generate the second field with the rails
helpers. I have tried:

<%=text_field "document" "asset[name]" %>
<%=text_field "document" "asset.name" %>

Is it possible to generate this kind of nested fields with helpers or
should I generated by hand?

Thanks in advance,

Rubén
extreme development, S.L.
Paseig del Ferrocarril 335, Planta 3
08860 Castelldefels

Tel.  93 145 87 20
Fax. 93 145 87 21
mrj (Guest)
on 2005-12-03 16:16
(Received via mailing list)
Rubén Gil wrote:

> <input type="text" name="document[name]" />
> <input type="text" name="document[asset][name]" />
>
> The question is: how can i generate the second field with the rails
> helpers. I have tried:
>
> <%=text_field "document" "asset[name]" %>
> <%=text_field "document" "asset.name" %>
>
> Is it possible to generate this kind of nested fields with helpers or
> should I generated by hand?

Three options:

1. Manual HTML
2. The text_field_tag helper, overriding the id tag if necessary
3. Install the Rails patch at http://dev.rubyonrails.org/ticket/2053

--
We develop, watch us RoR, in numbers too big to ignore.
ruben (Guest)
on 2005-12-05 12:16
(Received via mailing list)
Mark,

Thank you very much for your help.

Rubén Gil


extreme development, S.L.
Paseig del Ferrocarril 335, Planta 3
08860 Castelldefels

Tel.  93 145 87 20
Fax. 93 145 87 21



-----Mensaje original-----
De: removed_email_address@domain.invalid
[mailto:removed_email_address@domain.invalid] En nombre de Mark Reginald
James
Enviado el: sábado, 03 de diciembre de 2005 15:14
Para: removed_email_address@domain.invalid
Asunto: [Rails] Re: View helpers and nested attributes

Rubén Gil wrote:

> I have a model with two entities (document and asset) and a 1:1
> relationship defined between them (every model has an asset).
>
> I want to generate a rthml view that generates a hash for document
> attributes and a nested hash for asset attributes (for example
> {:document =>{:name=>XXX :asset => {date =>XXX}})
>
> According to the Pragmatic Programmers book (page 355), the input
fields
>
> Is it possible to generate this kind of nested fields with helpers or
> should I generated by hand?

Three options:

1. Manual HTML
2. The text_field_tag helper, overriding the id tag if necessary
3. Install the Rails patch at http://dev.rubyonrails.org/ticket/2053

--
We develop, watch us RoR, in numbers too big to ignore.

_______________________________________________
Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails
This topic is locked and can not be replied to.