Home>

I'm trying to implement a dynamic form using nasted_form.
I'm creating a recipe site and have a form for material and amount
I want to be able to add and delete.
Reference site[Rails] How to use nested_attributes

I was able to create a form, but it is not added when I press the add button.
There are no errors.

Corresponding source code
class Recipe</pre>
<pre><code>class Material</pre>
<pre><code>class RecipesController</pre>
<pre><code>           Recipe posting       <% = render partial: "form", locals: {recipe: @recipe}%>  
<% = nested_form_for recipe, url: recipes_path, local: true do | f |%>  <% = f.label: title, "Cooking name"%><br /><% = f.text_field: title, required: true%>    <% = f.label: text, "description"%><br /><% = f.text_area: text, required: true, class:: form__text%>  <% = f.fields_for: materials do | mf |%><% = mf.label: vegetable%><% = mf.text_field: vegetable%><% = mf.label: amount%><% = mf.text_field: amount%><% = mf.link_to_remove'I'll destroy you! '%><% end%><% = f.link_to_add'20m class ahead! ',: materials%>  <% = f.label: image, "cooking image"%><br /><% = f.file_field: image%>    <% = f.label: video, "Youtube URL"%><br /><% = f.text_field: video%>    <% = f.submit "submit", class :: form__btn%><% end%>
require ("@ rails/ujs"). start ()
require ("turbolinks"). start ()
require ("@ rails/activestorage"). start ()
require ("channels")
// = require jquery ← Addendum
// = require jquery_ujs ← Addendum
// = require jquery_nested_form
<head><meta name = "viewport" content = "width = device-width, initial-scale = 1.0" /><title>ProtoSpace</title><% = csrf_meta_tags%><% = csp_meta_tag%><% = stylesheet_link_tag'application', media:'all','data-turbolinks-track':'reload'%><script src = "http://code.jquery.com/jquery-3.3.1.min.js" defer></script>← Addendum
  <% = javascript_pack_tag'application','data-turbolinks-track':'reload'%><link href = "https://fonts.googleapis.com/css?family=Noto+Sans+JP:400,700,900&display=swap" rel = "stylesheet"></head>
What I tried

How to write a controller on the reference site

materials_attributes: [: amount,: vegetable]


It was, but when I check the git hub of nasted_form
It was written that id and destroy are required, so I added it.

materials_attributes: [: id,: amount,: vegetable,: _destroy]


However, there was no particular change.
You cannot add it, but you can save it to the table without any problem.

We apologize for the inconvenience, but please point out.

  • Answer # 1

    nested_form has been neglected since 2013
    The latest version of cocoon will be released in 2020.

    The ruby ​​toolbox is useful for checking the maintenance status of gem.