Disposición de bucle de rieles

So I have some loops going on, but im trying to organize how the information is displayed.

Im using bootstrap for the stylesheets.

Aquí está el bucle:

<% @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 %>

I cant get the school information to be posted in the same bootstrap well that users information is stored.

:(

preguntado el 11 de septiembre de 13 a las 23:09

What does the break between the user well and the school information well look like? Can you post another image? Also, what is the relationship between your User y App ¿modelo? -

2 Respuestas

Desde un User presumably has many apps, you'll want to iterate through each user's as you iterate through each user. Something like this may work:

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

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

<% end %>

ACTUALIZACIÓN:

Si un User solo tiene uno App, then there's no need to iterate through each user's apps, since there will only be one:

<% @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 %>

Respondido el 12 de Septiembre de 13 a las 00:09

I would recommend creating partials for each of the loop content

algo como esto

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

and create a partial _user.html.erb with the content

<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 />

Respondido el 11 de Septiembre de 13 a las 23:09

There are Rails shortcuts for this; you can just render user. - David Newton

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.