Marcelo Ruiz
2009-Mar-21 13:36 UTC
Dynamically generated form + Saving multiple records at once
Hi Everybody, My name is Marcelo Ruiz, software developer from Argentina starting to work with rails. I''m building a web app to track traffic information for roads. We have operators that create Reports associated to each Segment of different Roads. I have the following models: * Road (has_many :segments) * Segment (belongs_to :road has_many :reports) * Report (belongs_to :segment) The requirement is that I have to show up only one form per Road, so the operator can load the Reports for all the Segments in that Road at once. This would be something similar to this: Road "Route 55" ------------------------ Report for Segment 1: (text field) Report for Segment 2: (text field) Report for Segment 3: (text field) (SUBMIT BUTTON) This means that I will have to: 1. Dinamically generate the fields, according to the number of segments the selected Road has. 2. Create multiple Reports at the same time. Any advise on how to do this? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Freddy Andersen
2009-Mar-21 13:55 UTC
Re: Dynamically generated form + Saving multiple records at once
I think you will be happy to watch this screencast http://railscasts.com/episodes/75-complex-forms-part-3 Its a project that has_many tasks but it talks about exactly the problem you have with build_segments 3.times... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Marcelo Ruiz
2009-Mar-23 20:42 UTC
Re: Dynamically generated form + Saving multiple records at once
Thank you Freddy. That wasn''t exactly what I needed to do, but the screencasts helped me in another case. What I actually need to do is simpler: create multiple Reports at the same time. Each report has a description with a textfield and I have to associate it with a different segment. That''s all. Any help? Thanks! On 21 mar, 10:55, Freddy Andersen <fre...-RCI/mp9mI1I6GGFevw1D/A@public.gmane.org> wrote:> I think you will be happy to watch this screencast > > http://railscasts.com/episodes/75-complex-forms-part-3 > > Its a project that has_many tasks but it talks about exactly the > problem you have with build_segments 3.times...--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Marcelo Ruiz
2009-Mar-23 21:09 UTC
Re: Dynamically generated form + Saving multiple records at once
This is a code sample of what I have made so far: <h1>New Report for <%= @way.road.name%>, <%= @way.name%></h1> <%= form_tag :action => :create, :id => @way.id%> <p>Date: <%= datetime_select("report", "time") %> </p> <p>Priority: <%= radio_button("report", "priority", 1) %> high - <%= radio_button("report", "priority", 2, {:checked => "checked"}) %> medium - <%= radio_button("report", "priority", 3) %> low</p> <% for segment in @segments%> <%= hidden_field("report[]", "segment_id", { :value => segment.id}) %> <p>Segment: <strong><%= segment.name%></strong></p> <p>Traffic Status: <%= select("report[]", "status_id", Status.find(:all, :order => "Severity").map {|u| [u.name, u.id]}) %> </p> <p>Description:<br/> <%= text_area("report[]", "description", {:rows => 6, :cols => 70}) %></p> <p>Short Desc.:<br/> <%= text_area("report[]", "short_description", {:rows => 2, :cols => 70}) %></p> <% end %> <p><%= submit_tag %></p> </form> This form renders well. Notice how I have some fields of Report that are common to all segment reports (Hour and Priority) and some that vary (segment_id, status_id, description and short_description). I''m prefixing the first fields with "report" and the others with "report []". I''m not sure if it''s a good idea. Now I don''t have any idea how I should handle this in the controller. Any idea? Thanks! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---