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.
43335f8216edbe5342af1075ceec4d0a?d=identicon&s=25 ruben (Guest)
on 2005-12-01 17: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
C64e63b70be7dfed8b0742540b8b27e5?d=identicon&s=25 mrj (Guest)
on 2005-12-03 15: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.
43335f8216edbe5342af1075ceec4d0a?d=identicon&s=25 ruben (Guest)
on 2005-12-05 11: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: rails-bounces@lists.rubyonrails.org
[mailto:rails-bounces@lists.rubyonrails.org] En nombre de Mark Reginald
James
Enviado el: sábado, 03 de diciembre de 2005 15:14
Para: rails@lists.rubyonrails.org
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
Rails@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails
This topic is locked and can not be replied to.