hello, i would like to display a collection of records on one page (e.g. an author record with all his/her books). a record contains a text_area (e.g. a description of the book) and a date_select (e.g. when the book was published). <% for @book in @author.books %> <%= text_area ''book[]'', ''note'' %> <%= datetime_select ''book[]'', ''published_on'' %> <% end %> the text_field works nice, the generated code looks like: <textarea cols="40" id="book_12_desc" name="book[12][desc]">foo</textarea> the ID of a book record is there. BUT i do not know, how to achieve this with the date_select helper? the helper generates: <select name="book[published_on(2i)]"> <option value="00">00</option ... it should be name="book[12][published_on(2i)]" how to do that? (:prefix, :discard_type did not work for me) thanks ondrej
Mark Reginald James
2006-Jul-27 13:16 UTC
[Rails] Re: text_field and date_select in collection
Ondrej Jaura wrote:> i would like to display a collection of records on one page (e.g. an > author record with all his/her books). > ... > > BUT i do not know, how to achieve this with the date_select helper? > the helper generates: > > <select name="book[published_on(2i)]"> > <option value="00">00</option > ... > > it should be name="book[12][published_on(2i)]" > > > how to do that? (:prefix, :discard_type did not work for me)As the core code is currently written, you can''t use either auto or explicit indexing with date_select. You''ll have to use select_year, select_month, and select_day, using @book.published_on as their dates, prefix options set to "book[#{@book.id}]", and field_name options ''published_on(1i)'', ''published_on(2i)'', and ''published_on(3i)''. -- We develop, watch us RoR, in numbers too big to ignore.
Mark Reginald James wrote:> Ondrej Jaura wrote: > >> i would like to display a collection of records on one page (e.g. an >> author record with all his/her books). >> ... >> >> BUT i do not know, how to achieve this with the date_select helper? >> the helper generates: >> >> <select name="book[published_on(2i)]"> >> <option value="00">00</option >> ... >> >> it should be name="book[12][published_on(2i)]" >> >> >> how to do that? (:prefix, :discard_type did not work for me) > > As the core code is currently written, you can''t use either auto or > explicit indexing with date_select. You''ll have to use select_year, > select_month, and select_day, using @book.published_on as their dates, > prefix options set to "book[#{@book.id}]", and field_name options > ''published_on(1i)'', ''published_on(2i)'', and ''published_on(3i)''.thanks :) have a nice day ondrej