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 years ago, Updated 2 years ago, 52 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

 has_many:items
# 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

belongs_to:item
# Columns are kept different for each table.

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

PostsController

def new
    @post=current_user.posts.build
    @[email protected]
    @item.build_heading
    @item.build_content
    @item.build_movie
    @item.build_quate
end

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

form.html.erb

<%=form_for(@post)do|f|%>
    <%[email protected] y?%>
      <ul>
        <%@post.errors.full_messages.each do | msg|%>
        <li><%=msg%></li>
        <%end%>
      </ul>
    <%end%>

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

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

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

<%=f.hidden_field: user_id%>

<ulid="weight">
            <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>
        <ul>

  <divid="entry_list">
  </div>

  <%=f.fields_for @item do|m|%>
            <%=m.hidden_field:order,value:'0'%>

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

    <%=m.submit%>
  <%end%>
<%=f.submit%>
<%end%>

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


© 2024 OneMinuteCode. All rights reserved.