One Form for Creating Multiple Records under One Model

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

One Form for Creating Multiple Records under One Model

Julian Medina
Hello:

I have an interesting yet somewhat strange task. Currently, there is a form in my app which adds just single record for certifying tutors. The group wants a way for volume purchasing where a coordinator can login and add multiple tutors in one form. I was considering a nested form or form object but since the certificate actually follows the individual instead of coordinator, I am now thinking it is best if multiple records under the "Certifcation" model get created under a single form. I really don't see why I'd need an entirely separate model for this. Would I need to implement a "hacky" solution for this?

Any advice would be greatly appreciated.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/08b175b9-484e-4708-902b-44ab4d7c3373%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: One Form for Creating Multiple Records under One Model

Colin Law
On 28 June 2018 at 05:37, Julian Medina <[hidden email]> wrote:

> Hello:
>
> I have an interesting yet somewhat strange task. Currently, there is a form
> in my app which adds just single record for certifying tutors. The group
> wants a way for volume purchasing where a coordinator can login and add
> multiple tutors in one form. I was considering a nested form or form object
> but since the certificate actually follows the individual instead of
> coordinator, I am now thinking it is best if multiple records under the
> "Certifcation" model get created under a single form. I really don't see why
> I'd need an entirely separate model for this. Would I need to implement a
> "hacky" solution for this?

Remember you can have multiple actions on a controller which bring up
different forms. So you can have a separate action that brings up the
multi-record form.

Colin

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLtz4W9oRvtUiKkdx8cMPnV1zqLN%3DpkOgUMQveTbY4JZYw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: One Form for Creating Multiple Records under One Model

Walter Lee Davis
Also, if you wanted to stick to the REST actions in your controllers, you could have a separate controller (with no additional model): think TutorsController and MultipleTutorsController or something like that. Rails conditions you to think that a controller must be unique to its model, but controllers don't even need models if that's not what they are doing, and multiple controllers can help refine your routing around a single model -- think a ContentsController and an AdminContentsController, with the same Content model.

Walter

> On Jun 28, 2018, at 3:17 AM, Colin Law <[hidden email]> wrote:
>
> On 28 June 2018 at 05:37, Julian Medina <[hidden email]> wrote:
>> Hello:
>>
>> I have an interesting yet somewhat strange task. Currently, there is a form
>> in my app which adds just single record for certifying tutors. The group
>> wants a way for volume purchasing where a coordinator can login and add
>> multiple tutors in one form. I was considering a nested form or form object
>> but since the certificate actually follows the individual instead of
>> coordinator, I am now thinking it is best if multiple records under the
>> "Certifcation" model get created under a single form. I really don't see why
>> I'd need an entirely separate model for this. Would I need to implement a
>> "hacky" solution for this?
>
> Remember you can have multiple actions on a controller which bring up
> different forms. So you can have a separate action that brings up the
> multi-record form.
>
> Colin
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> To post to this group, send email to [hidden email].
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLtz4W9oRvtUiKkdx8cMPnV1zqLN%3DpkOgUMQveTbY4JZYw%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/6CF88F4E-158B-4D45-8A81-F2EC8EBA5161%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: One Form for Creating Multiple Records under One Model

Julian Medina
In reply to this post by Colin Law
Thanks! So essentially I could have a separate button for volume purchases which would bring up a different view? Would I then have a loop in my controller that would create records for each person who is getting certified?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/60b35430-aa5f-437c-ae32-b675052d893c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: One Form for Creating Multiple Records under One Model

Julian Medina
In reply to this post by Walter Lee Davis
This is an interesting approach. Thanks! Would I essentially just duplicate my current controller but add a loop within the volume controller so that records are created based on the number of individuals getting certified? I am assuming I’d need two separate views as well.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/124e670c-0f53-4115-a636-d4c3367f0c1b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: One Form for Creating Multiple Records under One Model

Colin Law
On 28 June 2018 at 21:51, Julian Medina <[hidden email]> wrote:
> This is an interesting approach. Thanks! Would I essentially just duplicate my current controller but add a loop within the volume controller so that records are created based on the number of individuals getting certified? I am assuming I’d need two separate views as well.

Obviously you need a view to show your form.  You shouldn't have to
duplicate any actions from the current controller as presumably this
controller will only have the one action in it - showing the form,
adding the records, and handling any errors.

Colin

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLtoJPcssx4bH1VDDDb6uydBjQ6NS6SYA38G9aW2KamtSQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: One Form for Creating Multiple Records under One Model

Colin Law
In reply to this post by Julian Medina
On 28 June 2018 at 21:49, Julian Medina <[hidden email]> wrote:
> Thanks! So essentially I could have a separate button for volume purchases which would bring up a different view? Would I then have a loop in my controller that would create records for each person who is getting certified?

Since you haven't quoted the previous message we don't know who this
is addressed to.  Assuming it was my suggestion that you could have a
different action in the same controller then presumably yes, that is
what you would do.  Of course the code can get tricky as you may have
to allow for problems saving the record for each one (caused by
validation errors) and work out how to handle that.

Colin

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLv%2BdMrVKXV7kz%2B47izzQTe859HnSs%3D7jZu259jNDAZWLw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: One Form for Creating Multiple Records under One Model

Julian Medina
Sorry, I couldn't find a quote button on the mobile version.

I have been thinking more about it. Perhaps I can simply rename my controller, model, and view to "Certification Application" or "Certification Request" then create a model for "Individual Name" and create a has_many relationship. Technically, a "Certification" cannot have many individual names. However, a "Certification Application" or "Certification Request" can easily have many individual names. I can then use the Cocoon gem and make a nested form. The biggest challenge I see is making each dynamically created field increase the quantity. Perhaps I should have hidden fields for quantity and price that can dynamically get adjusted. Then upon submission, those can be passed to the backend which will calculate the correct amount to send to Stripe. Does this sound like the right approach?

Thank you again for the assistance.

On Friday, June 29, 2018 at 12:33:15 AM UTC-7, Colin Law wrote:
On 28 June 2018 at 21:49, Julian Medina <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="ttHfqVK6AAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">julian....@...> wrote:
> Thanks! So essentially I could have a separate button for volume purchases which would bring up a different view? Would I then have a loop in my controller that would create records for each person who is getting certified?

Since you haven't quoted the previous message we don't know who this
is addressed to.  Assuming it was my suggestion that you could have a
different action in the same controller then presumably yes, that is
what you would do.  Of course the code can get tricky as you may have
to allow for problems saving the record for each one (caused by
validation errors) and work out how to handle that.

Colin

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/6310da63-39d6-4976-92cc-4cad6a9c9e09%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.