Rails 3 - Query result to Map for jQuery Array
I'm sure this is a stupid bug that I'm missing but I can't seem to get past this issue. I have a Query that selects two va开发者_如何学Clues Status and Count of items in that status. Query works fine it is mapping these results into a jQuery data: block. Here is what I have
This works
data: [
<% count_by_status.each do |c| %>
["<%= c[0] %>",<%= c[1] %>],
<% end %>
]
This does not because the " " around status is turning into "
<%= count_by_status.map{|status, count| [status, count.to_i] }.inspect %>
I'm sure it is a stupid error but if anyone can help. I have tried .html_safe, different formats..etc and it just keeps failing.
The ugly code works but the clean nice code doesn't..argh
UPDATED Still not sure why this works and the other actually escapes the code but this one works now
<%= raw count_by_status.map{|status, count| [status, count.to_i] }.inspect %>
Rails 3 escapes HTML unless you use pass it to the raw method or call the string's html_safe method.
精彩评论