PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, May 18, 2022

[FIXED] How to create a line space in a Rails partial view?

 May 18, 2022     line, partial, ruby-on-rails, views     No comments   

Issue

In my index.html.erb view, I have the following render to display each and every flight (without doing a .each:

<%= render @flights %>

However, as I have the flights partial written, all the flights are listed side-by-side. What I want is one flight listed per line. How do I create a line space after each flight?

<%= radio_button_tag :flight_id, flight.id %>
<%= flight.id %>
<%= flight.date.strftime("%B %d, %Y")  %>
<%= flight.date.strftime('%I:%M:%S %p') %>
<%= flight.from_airport.code %>
<%= flight.to_airport.code %>
<%= distance_of_time_in_words(flight.duration) %>

Solution

Why not use tables?

<table>
  <%= render @flights %>
</table>

and in your partial write

<tr>
  <td><%= radio_button_tag :flight_id, flight.id %></td>
  <td><%= flight.id %></td>
  <td><%= flight.date.strftime("%B %d, %Y")  %></td>
  <td><%= flight.date.strftime('%I:%M:%S %p') %></td>
  <td><%= flight.from_airport.code %></td>
  <td><%= flight.to_airport.code %></td>
  <td><%= distance_of_time_in_words(flight.duration) %></td>
</tr>

Arrgghhhh so much typing, and so error-prone. For educational purposes, why not use haml?

%table
  = render @flights

in your partial:

%tr
  %td= radio_button_tag :flight_id, flight.id 
  %td= flight.id 
  %td= flight.date.strftime("%B %d, %Y")  
  %td= flight.date.strftime('%I:%M:%S %p') 
  %td= flight.from_airport.code 
  %td= flight.to_airport.code 
  %td= distance_of_time_in_words(flight.duration) 


Answered By - nathanvda
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing