[Rails] Re: Dynamically generated form + Saving multiple records at once

2009-03-23 Thread Marcelo Ruiz

This is a code sample of what I have made so far:

New Report for <%= @way.road.name%>, <%= @way.name%>

<%= form_tag :action => :create, :id => @way.id%>

Date: <%= datetime_select("report", "time") %> 

Priority:
<%= radio_button("report", "priority", 1) %> high -
<%= radio_button("report", "priority", 2, {:checked => "checked"})
%>  medium -
<%= radio_button("report", "priority", 3) %> low

<% for segment in @segments%>

<%= hidden_field("report[]", "segment_id", { :value =>
segment.id}) %>

Segment: <%= segment.name%>

Traffic Status:
<%= select("report[]", "status_id", Status.find(:all, :order
=> "Severity").map {|u| [u.name, u.id]}) %>


Description:
<%= text_area("report[]", "description", {:rows => 6, :cols =>
70}) %>

Short Desc.:
<%= text_area("report[]", "short_description", {:rows =>
2, :cols => 70}) %>

<% end %>

<%= submit_tag %>



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@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: Dynamically generated form + Saving multiple records at once

2009-03-23 Thread Marcelo Ruiz

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  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@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---



[Rails] Re: Dynamically generated form + Saving multiple records at once

2009-03-21 Thread Freddy Andersen

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@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~--~~~~--~~--~--~---