I want to send only the elements of the child hierarchy form when submitting the child hierarchy and display them in the same view.

Asked 2 months ago, Updated 2 months ago, 2 views

Currently, Rails4 is developing user-posted applications, and we would like to create a feature that combines blocks of content such as Naver summary to create articles.

Therefore, the table configuration is as follows.

Post Table

# Column ↓
: name
: description

item table

 has_one: heading, content, movie, quote
# Column ↓
: order# This is the column that holds the order of items.
: post_id

heading, content, movie, quote table

# Columns are kept different for each table.

Then, specify it on the controller as shown below, and


def new
    @[email protected]

The hierarchical form is displayed in the view as shown below.


    <%[email protected] y?%>
        <%@post.errors.full_messages.each do | msg|%>

<%=f.label:Title %>
<%=f.text_field: title, placeholder: "Enter Post Title" %>

<%=f.text_field:description, placeholder: "Enter Post Summary" %>

<%=f.label: Upload Image %>
<%=f.file_field: image%>

<%=f.hidden_field: user_id%>

            <li>div><br><a class="widgetselectorbtn">headline</a></div><li>
            <li>div><br><a class="widgetselectorbtn">text</a><div><li>
            <li>div><br><a class="widgetselectorbtn">Youtube</a></div><li>
            <li>div><br><a class="widgetselectorbtn">quote</a><div><li>


  <%=f.fields_for @item do|m|%>

            <div class="ItemWidget01itemselected hide">
                  <%=render 'headings/form_fields', m:m%>
            <div class="ItemWidget01itemselected hide">
                  <%=render'contents/form_fields', m:m%>
            <div class="ItemWidget01itemselected hide">
                  <%=render 'movies/form_fields', m:m%>
            <div class="ItemWidget01itemselected hide">
                  <%=render 'quates/form_fields', m:m%>


When <%=m.submit%> is clicked this time, I would like to display the held data in the view and add other items while checking it.

I've looked into various methods, but I'm at a loss because I'm not sure.

Could someone help me?

ruby-on-rails ruby

2022-09-30 11:33

1 Answers

I think it would be good to implement a simple button in html that does not have a transmit function without writing submit with an html submit tag, and change the layout to display a confirmation screen somewhere in the view when a simple button is clicked in JavaScript.
Instead of actually sending it at first, it is recommended that you display the submit button that JavaScript hid when you finished adding the item.

2022-09-30 11:33

If you have any answers or tips

© 2022 OneMinuteCode. All rights reserved.