Saturday, May 15, 2010

[Rails] Rails 3 and html_safe

Is it just me or is html_safe a massive pain in the arse? Just trying
to do a simple helper.

def messages
messages = ''
[:error, :notice].each do |t|
if flash[t]
messages << content_tag(:p, flash[t], :class => t)
end
end
unless messages.blank?
content_tag(:div, messages)
end
end

cause an enormous amount of aggravation. I tried for hours to try and
find why it was escaping everything.

def messages
messages = ''.html_safe
[:error, :notice].each do |t|
if flash[t]
messages << content_tag(:p, flash[t].html_safe, :class => t)
end
end
unless messages.blank?
content_tag(:div, messages)
end
end

It would be nice if you could just html_safe right at the end of the
method but oooooh no.

Discuss?

--
Rob Lacey
contact@robl.me
http://www.robl.me

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate