# Insert multiple datasets - one form

**URL:** <https://discuss.rubyonrails.org/t/insert-multiple-datasets-one-form/65235>\
**Category:** rubyonrails-talk\
**Created:** [September 24, 2012, 1:11pm UTC](https://discuss.rubyonrails.org/t/insert-multiple-datasets-one-form/65235 "2012-09-24T13:11:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Googlemail](https://avatars.discourse-cdn.com/v4/letter/g/48db29/32.png) [@Googlemail](https://discuss.rubyonrails.org/u/Googlemail)\
**Post date:** [September 24, 2012, 1:11pm UTC](https://discuss.rubyonrails.org/t/insert-multiple-datasets-one-form/65235/1 "2012-09-24T13:11:15Z")

</div>

Hello…

I have a form:

\<%= form\_for @instruction\_user, :url =\> some\_path do |f|%\>

\<% @users.each do |user| %\> \<%= user.name %\>

\<%= f.input :prio, collection: 1…5, :as =\> :radio\_buttons%\> \<%= f.text\_field :remark%\> \<%= check\_box\_tag “instruction\_user\_ids”, “#{user.id}” %\>

controller: if params[:instruction\_user\_ids] params[:instruction\_user\_ids].each do|user\_id| InstructionUser.create( :user\_id =\> user\_id, :instruction\_id =\> params[:instruction\_id], :remark =\> ???, :prio =\> ??? ) end

1. The table rows are generated, but the attributes :prio\_tl and :remark\_tl are not in. How to write the … take the form\_fields?
2. Both attibutes need some indentifier!? I can not mark the radio-buttons per row seperately…as they have the same id… Would be great to get some idea about the best way to handle the form and controller.

Thanks a lot

---

<div class="post-metadata">

**Author:** ![David\_Angga](https://avatars.discourse-cdn.com/v4/letter/d/73ab20/32.png) [@David\_Angga](https://discuss.rubyonrails.org/u/David_Angga)\
**Post date:** [September 25, 2012, 1:59am UTC](https://discuss.rubyonrails.org/t/insert-multiple-datasets-one-form/65235/2 "2012-09-25T01:59:36Z")

</div>

Hi Werner,

my dirty solution 🙂

\<%= f.input :prio, :as =\> :hidden %\>

\<%= radio\_button\_tag :prio\_tmp, 1, :onclick =\> “updatePrioHiddenValue(this.value)” %\>

\<%= radio\_button\_tag :prio\_tmp, 2, :onclick =\> “updatePrioHiddenValue(this.value)” %\> …

…

using javascript function to update the :prio hidden value on radio button click.

---

<div class="post-metadata">

**Author:** ![Googlemail](https://avatars.discourse-cdn.com/v4/letter/g/48db29/32.png) [@Googlemail](https://discuss.rubyonrails.org/u/Googlemail)\
**Post date:** [September 25, 2012, 11:12am UTC](https://discuss.rubyonrails.org/t/insert-multiple-datasets-one-form/65235/3 "2012-09-25T11:12:16Z")

</div>

Thanks David… may be I have to describe it better …

the form:

\<%= form\_for @instruction\_user, :url =\> some\_path do |f|%\>

\<% @users.each do | user | %\>

\<%= f.input :prio, collection: 1…5, :as =\> :radio\_buttons%\>

\<%= f.text\_field :remark%\>

\<%= check\_box\_tag “instruction\_user\_ids”, “#{[user.id](http://user.id/)}” %\>

controller:

params[:instruction\_user\_ids].each do| user\_id |

InstructionUser.create(…:remark =\> ???, :prio =\> ???

1. The f.text\_field :remark returns nothing because its getting overwritten by empty remark fields …needs some . How is the best way?

Tried “text\_field\_tag” and fields\_for instruction with no success. I don’t know how to access the val in the controller.

1. Same with the radio buttons prio + the problem to mark the each line separately…

Would be great to get some idea…

Thanks

> Hi Werner,

> my dirty solution 🙂

> 

> \<%= f.input :prio, :as =\> :hidden %\>

> \<%= radio\_button\_tag :prio\_tmp, 1, :onclick =\> “updatePrioHiddenValue(this.value)” %\>
> 
> \<%= radio\_button\_tag :prio\_tmp, 2, :onclick =\> “updatePrioHiddenValue(this.value)” %\> …

> …

> 

> using javascript function to update the :prio hidden value on radio button click.
> 
> >

> > Hello…
> > 
> > I have a form:
> > 
> > \<%= form\_for @instruction\_user, :url =\> some\_path do |f|%\>
> > 
> > \<% @users.each do |user| %\> \<%= [user.name](http://user.name/) %\>
> > 
> > \<%= f.input :prio, collection: 1…5, :as =\> :radio\_buttons%\> \<%= f.text\_field :remark%\> \<%= check\_box\_tag “instruction\_user\_ids”, “#{[user.id](http://user.id/)}” %\>
> > 
> > controller: if params[:instruction\_user\_ids] params[:instruction\_user\_ids].each do|user\_id| InstructionUser.create( :user\_id =\> user\_id, :instruction\_id =\> params[:instruction\_id], :remark =\> ???, :prio =\> ???
> > 
> > ```
> > )
> > end
> > 
> > ```
> > 
> > 1. The table rows are generated, but the attributes :prio\_tl and :remark\_tl are not in. How to write the … take the form\_fields?
> > 2. Both attibutes need some indentifier!? I can not mark the radio-buttons per row seperately…as they have the same id…
> > 
> > Would be great to get some idea about the best way to handle the form and controller.
> > 
> > Thanks a lot
> > 
> > –
> > 
> > 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](mailto:rubyonrails-talk@googlegroups.com).
> > 
> > To unsubscribe from this group, send email to [rubyonrails-talk+unsubscribe@googlegroups.com](mailto:rubyonrails-talk+unsubscribe@googlegroups.com).
> > 
> > To view this discussion on the web visit [https://groups.google.com/d/msg/rubyonrails-talk/-/ieqWfqlz2MoJ](https://groups.google.com/d/msg/rubyonrails-talk/-/ieqWfqlz2MoJ).
> > 
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

> 

> – **David Angga Prasetya** _RoR Developers_

> skype: david.angga

> phone: +62 85 222 1 5555 2

> 

> 

> –
> 
> 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](mailto:rubyonrails-talk@googlegroups.com).
> 
> To unsubscribe from this group, send email to [rubyonrails-talk+unsubscribe@googlegroups.com](mailto:rubyonrails-talk+unsubscribe@googlegroups.com).
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

Werner Laude

[webagentur.laude@gmail.com](mailto:webagentur.laude@gmail.com)

---

<div class="post-metadata">

**Author:** ![Avi](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Avi](https://discuss.rubyonrails.org/u/Avi)\
**Post date:** [September 25, 2012, 11:34am UTC](https://discuss.rubyonrails.org/t/insert-multiple-datasets-one-form/65235/4 "2012-09-25T11:34:36Z")

</div>

You can try using simple\_form\_for instead of form\_for. Check this link :- [https://github.com/plataformatec/simple\_form](https://github.com/plataformatec/simple_form)

---

<div class="post-metadata">

**Author:** ![Googlemail](https://avatars.discourse-cdn.com/v4/letter/g/48db29/32.png) [@Googlemail](https://discuss.rubyonrails.org/u/Googlemail)\
**Post date:** [September 25, 2012, 11:50am UTC](https://discuss.rubyonrails.org/t/insert-multiple-datasets-one-form/65235/5 "2012-09-25T11:50:20Z")

</div>

> You can try using simple\_form\_for instead of form\_for. Check this link :- [https://github.com/plataformatec/simple\_form](https://github.com/plataformatec/simple_form)
> 
> > \<%= form\_for @instruction\_user, :url =\> some\_path do |f|%\>
> > 
> > \<% @users.each do |user| %\> \<%= [user.name](http://user.name/) %\>

I have tried:

\<%= form\_tag new\_fb\_instruction\_users\_path, :method =\> :post do %\>

…

\<%= simple\_fields\_for “instruction”, @instruction\_user do |f| %\>

\<%=f. input "remark%\>

controller: …:remark =\> params[:instruction][:remark]

log: “instruction”=\>[{“remark”=\>“test”}

=\> can’t convert Symbol into Integer

phh…

> > \<%= f.input :prio, collection: 1…5, :as =\> :radio\_buttons%\>

> > \<%= f.text\_field :remark%\> \<%= check\_box\_tag “instruction\_user\_ids”, “#{[user.id](http://user.id/)}” %\>
> > 
> > controller: if params[:instruction\_user\_ids] params[:instruction\_user\_ids].each do|user\_id| InstructionUser.create( :user\_id =\> user\_id, :instruction\_id =\> params[:instruction\_id], :remark =\> ???, :prio =\> ??? ) end
> > 
> > 1. The table rows are generated, but the attributes :prio\_tl and :remark\_tl are not in. How to write the … take the form\_fields?
> > 2. Both attibutes need some indentifier!? I can not mark the radio-buttons per row seperately…as they have the same id… Would be great to get some idea about the best way to handle the form and controller.
> > 
> > Thanks a lot

> –
> 
> 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](mailto:rubyonrails-talk@googlegroups.com).
> 
> To unsubscribe from this group, send email to [rubyonrails-talk+unsubscribe@googlegroups.com](mailto:rubyonrails-talk+unsubscribe@googlegroups.com).
> 
> To view this discussion on the web visit [https://groups.google.com/d/msg/rubyonrails-talk/-/SmaL6Oh6LMIJ](https://groups.google.com/d/msg/rubyonrails-talk/-/SmaL6Oh6LMIJ).
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

Werner Laude

[webagentur.laude@gmail.com](mailto:webagentur.laude@gmail.com)
