Ruby on Rails Sunday, July 21, 2019

You'll have to assign the values you get back (in JavaScript) to a properly-named form element in your form. Try making a hidden input in the form with the name set to meal[meal_item_ids]. Then locate that field in JavaScript in your callback function (which fires after the drop event) and set the value of that hidden field to the array of values you get in your callback.

Walter

> On Jul 20, 2019, at 9:24 PM, John Sanderbeck <bandor535@gmail.com> wrote:
>
> I understand that part Walter. I have done many nested forms. However, this is the first one with a drag and drop feature.
>
> The part I am struggling with is how to populate the array that gets passed back through the drag and drop events.
>
> I have the strong params setup and could easily just add a simple nested form, but I wanted to add the drag and drop as a feature so they could build the meals easily with an IPad.
>
> John
>
> On Saturday, July 20, 2019 at 8:59:21 PM UTC-4, Walter Lee Davis wrote:
> I'm not sure how your form is constructed at the moment. But if you were passing the result of the dragged items back to a meals_controller, you could assign the array of values to `menu_item_ids` and the child menu items would be created and assigned. You'll have to ensure that you whitelist that attribute in a special way:
>
> def meal_params
> params.permit(:foo, :bar, :baz, menu_item_ids: [])
> end
>
> You'll want to put this (and any other array-shaped parameters) at the end of the list of permitted params, and you have to cast it to an array as I've done here.
>
> If you are sending the form to the menus_controller, then you've got a doubly-nested assignment going on, and you'll probably want to use accepts_nested_parameters_for in your model relationship between menu and meal. I would do that if I was building N number of meals within one menu form. If you're trying to get this going first, I would just save each meal individually first, and then, once it's working at that level, try to further complicate it by nesting forms.
>
> Walter
>
> > On Jul 20, 2019, at 12:25 PM, John Sanderbeck <band...@gmail.com> wrote:
> >
> > Ok. Changed to Document.ready and got the drag and drops firing...
> >
> > Also changed the data URl to be a data ID which is the ID of the meal item.
> >
> > The part I am unsure of is assigning the mitem array that gets passed back in the form...
> >
> > I know this should be simple and as you can tell I am a total newbie with this... :-)
> >
> > John
> >
> > On Friday, July 19, 2019 at 10:48:56 AM UTC-4, John Sanderbeck wrote:
> > I have an app in production that I am adding a module to for Lunch Ordering
> >
> > What I have is a Menu, which has Meals, and the Meals have Meal Items in Categories like Entree, Vegetable, Fruit, and Drink
> >
> > What I would like to do it allow Drag and Drop to build meals, and Drag and Drop to build Menus
> >
> > I made a standard Rails form with a Drag and Drop area for the meal with the items as draggable and sorted in groups on the right....
> >
> > I don't think I need an Ajax call as I am building or editing the meal. What I need to be able to do is manipulate the array that gets passed back for the Meal Items...
> >
> > Any suggestions or links I can look at to do this?
> >
> > John Sanderbeck
> >
> >
> >
> >
> >
> > --
> > 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 rubyonra...@googlegroups.com.
> > To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/f0ec2c68-3c7d-40db-85f4-52ff4ab3866c%40googlegroups.com.
>
>
> --
> 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 rubyonrails-talk+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/faf99154-a737-4d91-a7e9-95b973e7ed69%40googlegroups.com.

--
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 rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/A020658F-511F-4B21-BB23-AE3AA9F2C0F0%40wdstudio.com.

No comments:

Post a Comment