Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to organize data fields within a HTML table?
    text
    copied!<p>I'm building a view to manage two models, <code>Doctor</code> and <code>Schedule</code>. </p> <p>I want to create a <code>html</code> table to hold these fields. each column(day) should hold the eight hours so it can be user friendly.</p> <p>Example:</p> <pre><code>--------------------------------------------------------------------------------------------- Sunday ! Monday ! Tuesday ! Wednesday ! Thursday ! Friday ! ... --------------------------------------------------------------------------------------------- hour1 hour1 hour1 hour1 hour1 hour1 hour2 hour2 hour2 hour2 hour2 hour2 ... ... ... ... ... ... hour8 hour8 hour8 hour8 hour8 hour8 --------------------------------------------------------------------------------------------- </code></pre> <p>_form</p> <pre><code>&lt;% @rows_per_column = 18 %&gt; &lt;% @columns = 7 %&gt; &lt;table class="table"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;th&gt;Sunday&lt;/th&gt; &lt;th&gt;Monday&lt;/th&gt; &lt;th&gt;Tuesday&lt;/th&gt; &lt;th&gt;Wednesday&lt;/th&gt; &lt;th&gt;Thursday&lt;/th&gt; &lt;th&gt;Friday&lt;/th&gt; &lt;th&gt;Saturday&lt;/th&gt; &lt;/tr&gt; &lt;% 0.upto(@rows_per_column).each do |row| %&gt; &lt;tr&gt; &lt;%= f.fields_for :schedules do |builder| %&gt; &lt;% 0.upto(@columns - 1).each do |column| %&gt; &lt;% index = row + (column * @rows_per_column) %&gt; &lt;td&gt;&lt;%= index %&gt; &lt;div class="field"&gt; &lt;%= builder.label :day %&gt; &lt;/div&gt; &lt;/td&gt; &lt;% end %&gt; &lt;% end %&gt; &lt;/tr&gt; &lt;% end %&gt; &lt;/tbody&gt; &lt;/table&gt; </code></pre> <p>My idea is to assign a default value through an array to each day and and each hour, the table <code>Schedule</code> has a is_available column to set the doctor hour availability (a boolean).</p> <p>I've been trying to tackle this with a nested loop but I can not get it to work right. Any idea on how could I achieve this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload