I’ve been banging my head for the last two days trying to figure this out and I finally narrowed down the source.
I’m using a helper to generate the html for my sidebar and using html_safe on the return value. When I have the html structured just the right way, it causes my controller action to fire twice (I saw it first when I was getting two records inserted into my db from my action and then I verified using ruby-debug). Here’s the helper code:
def get_sidebar
first = String.new
second = String.new
str = String.new
str+= "<a href=''><img src='" << first << second << "'></a>"
str.html_safe
end
If I modify str and remove the img tag from before and after the concat’d vars, it only fires once. If the concat’d vars aren’t empty, it only fires once (these were originally coming out of non-nullable db columns but were empty strings). And if I don’t call the html_safe method, it only fires once…
Any ideas what is going on here? Is this expected behavior for html_safe? Am I crazy?
Thanks in advance!
use content_tag instead of html_safe