0

所以我有一些循环正在进行,但我试图组织信息的显示方式。

我为样式表使用引导程序。

这是循环:

<% @users.each do |i| %>
        <h3><%= i.firstname %><%= i.lastname %></h3>
        Birthday: <%= i.dateofbirth %><br />
        Address: <%= i.address %><br />
        City: <%= i.city %><br />
        Province: <%= i.province %><br />
        Phone Number: <%= i.phonenumber %><br />
        Service Provider: <%= i.serviceprovider %><br />
        Gender: <%= i.gender %><br />
        Languages: <%= i.languages %><br />
  <% end %>



  <% @apps.each do |f| %>

        <h3>School Information</h3>
        Highschool: <%= f.highschool %><br />
        Address: <%= f.highschool_address %><br />
        City: <%= f.highschool_city %><br />
        Province: <%= f.highschool_province %><br />
        Postal Code: <%= f.highschool_postalcode %><br />



        <h4>Post Secondary Schools of Interest</h4>
        <% f.postsecondaries.each do |ps| %>
        Post Secondary Name: <%= ps.postsecondary %><br />
        Address: <%= ps.postsecondary_address %><br />
        City: <%= ps.postsecondary_city %><br />
        Province: <%= ps.postsecondary_province %><br />
        Postal Code: <%= ps.postsecondary_postalcode %><br />
        Country: <%= ps.postsecondary_country %><br />
        Program: <%= ps.postsecondary_program %><br />
        Faculty: <%= ps.postsecondary_faculty %><br />
        Status: <%= ps.postsecondary_status %><br />
        <% end %>




        <h3>Grades</h3>
        <% f.grades.each do |grade| %>
        <br />Course: <%= grade.course %><br />
        Grade: <%= grade.course_grade %>
        <% end %>

        <h3>Extracurricular Activities</h3>
        <% f.extra_activities.each do |e| %>
        Activity: <%= e.activity %><br />
        Position: <%= e.activity_position %><br />
        Dates: <%= e.activity_dates %><br />
        Times Per Week: <%= e.activity_timeperweek %><br />
        Contact Name: <%= e.activity_contact %><br />
        Contact Position: <%= e.activity_contact_position %><br />
        Contact Phone Number: <%= e.activity_contact_phonenumber %><br />
        Contact Email: <%= e.activity_contact_email %><br />
        Description: <%= e.activity_description %>
        <% end %>

        <h3>Paragraph</h3>
        Recall a time... <%= f.recall_a_time %><br />
        Description: <%= f.paragraph_description %>
        <br />Recall a time... <%= f.recall_a_time_two %><br />
        Description: <%= f.paragraph_description_two %>
        <br />Recall a time... <%= f.recall_a_time_three %><br />
        Description: <%= f.paragraph_description_three %>
  <% end %>

我无法将学校信息发布在存储用户信息的同一引导程序中。

:(

4

2 回答 2

0

由于一个User可能有许多应用程序,因此您需要在遍历每个用户时遍历每个用户的应用程序。像这样的东西可能会起作用:

<% @users.each do |user| %>
    <!-- iterate through user attributes -->

    <% user.apps.each do |app| %>
        <!-- iterate through app attributes -->
    <% end

<% end %>

更新

如果 aUser只有一个App,则无需遍历每个用户的应用程序,因为只有一个:

<% @users.each do |user| %>
    <!-- iterate through user attributes -->

    <h3>School Information</h3>
    Highschool: <%= user.app.highschool %><br />
    Address: <%= user.app.highschool_address %><br />
    City: <%= user.app.highschool_city %><br />
    Province: <%= user.app.highschool_province %><br />
    Postal Code: <%= user.app.highschool_postalcode %><br />

<% end %>
于 2013-09-11T22:29:25.247 回答
0

我建议为每个循环内容创建部分

像这样的东西

<% @users.each do |i| %>
    <%= render 'users' , locals : { i : i } %>
  <% end %>

并使用内容创建部分 _user.html.erb

<h3><%= i.firstname %><%= i.lastname %></h3>
Birthday: <%= i.dateofbirth %><br />
Address: <%= i.address %><br />
City: <%= i.city %><br />
Province: <%= i.province %><br />
Phone Number: <%= i.phonenumber %><br />
Service Provider: <%= i.serviceprovider %><br />
Gender: <%= i.gender %><br />
Languages: <%= i.languages %><br />
于 2013-09-11T22:12:33.763 回答