I have the following code that should show the value for the display field in my view:
<% @product.options.each do |o| %>
<tr>
<td class="option">
<%= o.display %>
...
But the o.display part doesn’t work for the very first option record. On all other options, it correctly prints the display value, but not on the very first one. I have verified in MySQL that a value exists for that particular option (Option 1):
mysql> select id,title,display from options;
+----+-----------------------------+---------+
| id | title | display |
+----+-----------------------------+---------+
| 1 | Option 1 | 1 |
| 2 | Option 2 | 2 |
| 3 | Option 3 | 3 |
+----+-----------------------------+---------+
What am I doing wrong here?
More info:
If I add:
<%= debug o %>
before trying to print the display field, it not only shows debug information, but shows the display value properly. With no debugging, it won’t show the display value.
display is a method of the Object class in Ruby and this created a problem with ActiveRecord I guess. Maybe you could change the name of that field, it should be the simpler option.