Dynamically displaying the column values
<p>Here, I have 10 columns i.e., <code>answer1, answer2, answer3, ..., answer10</code> in the table <code>MgAnswer</code>.
I have to check whether each column value is present or not. Only if it present,then I have to display it in the page.</p>

<p>Im giving column names dynamically within for loop</p>

<pre><code>&lt;% (1..10).each do |i| %&gt;
   &lt;% if MgAnswer."answer#{i}".present? %&gt;
      &lt;%= MgAnswer."answer#{i}" %&gt;
   &lt;% end %&gt;
&lt;% end %&gt;
</code></pre>

<p>Im ending up with Syntax error.</p>