本文介绍了在 rails 中查看管理员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个父表、子表、资金表.家长登录,添加他的孩子,然后为每个孩子申请资助.

父.rb

class Parent <申请记录has_many :children, 依赖: :destroyhas_many :secondaryparents, 依赖: :destroy结尾

funding.rb

课程资助

child.rb

class Child 申请记录归属地:父母has_many :fundings, 依赖: :destroy结尾

Parent 有一个字段作为 admin.如果设置为真正的父作为管理员.application.html.erb 是管理员的视图.我能够在彼此面前展示所有主要的父母和他们的孩子.我需要帮助在他们面前展示孩子们的资助申请.

application.html.erb

<!-- .main_column_css --><div class="col-sm-9 col-xs-12"><div class="content" role="main" id="main-content"><文章><div ><h1>应用状态</h1><div class="table-responsive"><table class="table table-bordered"><头><tr><th>主父名称</th><!-- <th>财务状况</th>--><th>子名称</th><th>活动</th><th>组织</th>第提交日期请求的金额<th>可用资金</th><th>状态</th></tr></thead><% @parents.each 做 |parent|%><% parent.children.each do |child|%><tr><td><%= parent.parent_1_firstname %></td><td><%= child.firstname %></td></tr><%结束%><%结束%></tbody>

<div class="clearfix"></div>

</文章>

<!-- .content -->

财务状况、活动、活动开始日期、提交日期、请求金额、可用资金都是资金表的字段.资金表有 child_id.子表有 parent_id.请帮忙

更新

解决方案

you can do child.fundings.each do |funding|然后为资金做所有属性.

I have a parent table, child Table, funding table. Parent logs in, add his children and then apply for funding for each child.

parent.rb

class Parent < ApplicationRecord
    has_many :children, dependent: :destroy
    has_many :secondaryparents, dependent: :destroy
end

funding.rb

class Funding < ApplicationRecord
    has_many :organisations, dependent: :destroy
    belongs_to :child
end

child.rb

class Child < ApplicationRecord
    belongs_to :parent
    has_many :fundings, dependent: :destroy
end

Parent has a field as admin. if set as true parent acts as admin. application.html.erb is the view of admin. I am able to display all the primary parents and their children in front of each other. I need help with displaying the funding applications of the children in front of them.

application.html.erb

<div class="row">
<!-- .main_column_css -->
  <div class="col-sm-9 col-xs-12">
    <div class="content" role="main" id="main-content">
      <article>
        <div ><h1>Application Status</h1>
            <div class="table-responsive">
              <table class="table table-bordered">
                <thead>
                  <tr>
                   <th>Primary Parent Name</th>
                   <!--  <th>Financial Status</th> -->
                    <th>Child Name</th>
                    <th>Activity</th>
                    <th>Organisation</th>
                    <th>Activity Start Date</th>
                    <th>Date Submitted</th>
                    <th>Amount Requested</th>
                    <th>Funds Available</th>
                    <th>Status</th>
                  </tr>
                </thead>
                <tbody>
  <% @parents.each do |parent| %>
    <% parent.children.each do |child| %>
      <tr> 
        <td><%= parent.parent_1_firstname %></td>
        <td><%= child.firstname %></td>

      </tr>
    <% end %>
  <% end %>
</tbody>      
              </table>
            </div>
            <div class="clearfix"></div>
          </div>           
      </article>
    </div>
    <!-- .content -->
  </div>
</div>

financial status, activity, activity start date, date submitted, amount requested, funds available are all fields of funding table. Funding table has the child_id. child table has parent_id. Kindly help

Update

<% @parents.each do |parent| %>
    <% parent.children.each do |child| %>
     <% child.fundings.each do |funding| %>
      <tr> 
        <td><%= parent.parent_1_firstname %></td>
        <td><%= child.firstname %></td>
        <td><%= funding.type_of_activity %></td>
      </tr>
    <% end %>
  <% end %>
<% end %>
解决方案

you can do child.fundings.each do |funding| and then do all the attributes for funding.

这篇关于在 rails 中查看管理员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 17:04