I''ve just updated the ''Four Days on Rails'' tutorial which I wrote back in March to bring it up to date with changes in Rails etc. The new version is downloadable from http://rails.homelinux.org as before (I have had an kind offer to convert it to a wiki, which would be great). I had a lot of feedback from readers of the original - the most frequently asked question was how to update multiple records of a table from a single screen. I''ve given one solution in an Appendix in ''Four Days'', but I''d be grateful if anyone could suggest a more elegant solution. As always, feedback very welcome - probably best direct to me to avoid unnecessary noise on the list. John
On Jun 13, 2005, at 2:00 PM, John McCreesh wrote:> I''ve just updated the ''Four Days on Rails'' tutorial which I wrote back > in March to bring it up to date with changes in Rails etc. The new > version is downloadable from http://rails.homelinux.org as before (I > have had an kind offer to convert it to a wiki, which would be great). > > I had a lot of feedback from readers of the original - the most > frequently asked question was how to update multiple records of a > table > from a single screen. I''ve given one solution in an Appendix in ''Four > Days'', but I''d be grateful if anyone could suggest a more elegant > solution. > > As always, feedback very welcome - probably best direct to me to avoid > unnecessary noise on the list. > > John > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >There is actually a way to generate the kind of HTML you posted in the appendix: <%= check_box "item[]", "done" %> The [] automatically get replaced with the object''s id in square brackets. Duane Johnson (canadaduane)
> There is actually a way to generate the kind of HTML you posted in > the appendix: > > <%= check_box "item[]", "done" %> > > The [] automatically get replaced with the object''s id in square > brackets.Can you point me to where this is documented? "[]" seems to have some special rails-fu magic in a couple contexts that I''ve not been able to pin down...
On Jun 13, 2005, at 9:46 PM, Michael Campbell wrote:> Can you point me to where this is documented? "[]" seems to have some > special rails-fu magic in a couple contexts that I''ve not been able to > pin down...This came out with Rails 0.9.5. Here''s a comment by DHH in the release: Create and update collections: Through calls like text_field "student []", "last_name", it’s now much easier to get input tags like input name="student[123][last_name]"..., which together with the fact that Base#create, Base#update, Base#destroy, Base#delete, AssociationCollection#build, and AssociationCollection#create now all accept arrays enables handling of many records at once. See http://weblog.rubyonrails.com/archives/category/releases/ And this is in the CHANGELOG: * Added support for automatic id-based indexing for lists of items #532 [dblack]. Example: <% @students.each do |@student| %> <%= text_field "student[]", "first_name", :size => "20" %> <%= text_field "student[]", "last_name" %> <%= text_field "student[]", "grade", :size => "5" %> <% end %> ...would produce, for say David Black with id 123 and a grace of C+: <input id="student_123_first_name" name="student[123] [first_name]" size="20" size="30" type="text" value="David" /> <input id="student_123_last_name" name="student[123][last_name]" size="30" type="text" value="Black" /> <input id="student_123_grade" name="student[123][grade]" size="5" type="text" value="C+" /> See http://dev.rubyonrails.com/file/tags/rel_0-9-5/actionpack/ CHANGELOG?rev=516 This is certainly something that should be better documented, however. I can''t seem to find it anywhere in the docs. Duane Johnson (canadaduane)
On 6/14/05, Duane Johnson <duane.johnson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Jun 13, 2005, at 9:46 PM, Michael Campbell wrote: > > Can you point me to where this is documented? "[]" seems to have some > > special rails-fu magic in a couple contexts that I''ve not been able to > > pin down... > > This came out with Rails 0.9.5. Here''s a comment by DHH in the release: >...> And this is in the CHANGELOG:...> This is certainly something that should be better documented, > however. I can''t seem to find it anywhere in the docs.Amen to that; I''ve USED this array feature (thanks to IRC folks), but since I started in rails late in the game, have assumed that the API docs would be the canonical spot for this sort of stuff and I STILL can''t find it anywhere; glad to know that might be because it''s not there. =) Thanks