The following rails helper method aims to give a select menu with options that have the background of the value (which represents a color)
def options_with_colors(colors)
colors.collect do |color, label|
"<option value='#{label}' style='background-color:#{label};'>#{color}</option> "
end.join
end
and called via @bg_colors = Categoryminor.where(categorymajor_id: categorymajor.id).all.pluck(:label, :name)
is generating the following HTML block
<select name="choice[bg_color]" id="choice_bg_color">
<option value='#FFC0CB' style='background-color:#FFC0CB;'>pink</option>
<option value='#FFC0CB' style='background-color:#FFC0CB;'>lavender</option>
<option value='#FFA07A' style='background-color:#FFA07A;'>light_salmon</option>
[...]
<option value='#DCDCDC' style='background-color:#DCDCDC;'>gainsboro</option>
<option value='transparent' style='background-color:transparent;'>transparent</option>
</select>
as visualised in the browser console window. I did notice that in pasting the code in the SO editing window, <
and >
were escaped to <
and >
The actual rendering appears as
The code appears rendered correctly, why is it not view-rendered and how can this be set properly?
2