Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here are a few hints, merely to give a few pointers on Ruby methods.</p> <pre><code># Original &lt;%= @myquiz.each do |x| puts "&lt;div&gt;" . x.quiz_ID . "&lt;/div&gt;" end %&gt; </code></pre> <p><code>&lt;%= expression %&gt;</code> will cause the expression to be visible in the HTML. Thus you'll have to manipulate the return value of your expression. You're using <code>.each</code> there, while for this purpose <strong><code>.map</code></strong> is more suitable, as it will return an array with the output of the block for each input variable. </p> <p>In the block the last statement is the <strong>return value</strong>, no need to print stuff someway.</p> <p>In the end, an array like <code>['A', 'B', 'C']</code> will still want to be joined by some line breaks stuff, so the expression would need to be joined with <strong><code>.join('&lt;br /&gt;')</code>.</strong></p> <p>This is a hell of a mess, but anyway, here it is:</p> <pre><code>&lt;%= @myquiz.map {|x| "&lt;div&gt;#{ x.quiz_id }&lt;/div&gt;" }.join("&lt;br /&gt;").html_safe %&gt; # or &lt;%= @myquiz.map(&amp;:quiz_id).map { |id| "&lt;div&gt;#{ id }&lt;/div&gt;" }.join("&lt;br /&gt;").html_safe %&gt; </code></pre> <p><strong>Don't do this at home. Seriously. Just note how .map works, how it collects return values (the last statement), and how to join array elements to form a string.</strong></p> <p><em>Further options:</em></p> <p>What would DHH do? Presumably go with the extra brackets, or move the logic somewhere else (into a helper or decorator) and just output some kind of <code>&lt;%= quiz_results %&gt;</code>.</p> <p>What would I do? Take a look at <a href="http://slim-lang.com/" rel="nofollow"><strong>Slim</strong></a> and <code>slim-rails</code> for integrating it and auto-generating <code>.html.slim</code> views.</p> <pre><code># In a slim view - @quizzes.each do |quiz| div = quiz.id </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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