I have an ActiveRecord model (called Festival) that contains an array of "FestDate" objects serialized into a sql text column of the Festival object. (like the Agile book first edition describes on p. 205) The FestDate objects themselvs are not ActiveRecord objects. (of course, otherwise they would be in their own table...) When working with a Festival, I would like to use various kinds of form helpers while iterating over the various FestDate objects. For example, I would like to use select_hour and select_minute tags, but when I do, they all end up having the same name. I am supposing this is because I am not iterating over an AR object, but one of my own creation. Also, when I try to use the check_box helper, it does not correctly pick up the value of boolean fields in the FestDate object. Again, this is because I am not working with an AR object. Is there any way to make this work? I suppose I could go to the trouble to make these FestDate object into AR objects, and store them in their own table, and setup the relationship, but it seems an awful lot of trouble... just so the helpers will work. If anyone has any ideas, I would be grateful. Shelby -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060716/c59f3518/attachment.html
Mark Reginald James
2006-Jul-17 04:03 UTC
[Rails] Re: form helpers with non-ActiveRecord objects
Shelby Westman wrote:> I would like to use select_hour and select_minute tags, but when I do, > they all end up having the same name. I am supposing this is because I > am not iterating over an AR object, but one of my own creation.Use the :prefix option to give them different names.> Also, when I try to use the check_box helper, it does not correctly pick > up the value of boolean fields in the FestDate object. Again, this is > because I am not working with an AR object.You should be able to use AR helpers like check_box with your custom FestDate objects. Just make sure to assign each object to a view instance variable before calling the helper. e.g. <% @festival.fest_dates.each_with_index do |@fest_date, i| %> <%= check_box :fest_date, :boolean_method, :index => i %> <% end %> -- We develop, watch us RoR, in numbers too big to ignore.