Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 unwanted html escaping

I am converting my fat Rails2 application to run on Rails3. After a long intense fight with an army of bugs and my bosses yells, the page is all rendered as an escaped html string. So all the divs, images etc. are written literally for the user.

For some reason this call of a partial renders an escaped string

<%= render :partial => 'something_really_interesting' %>

As all Ruby on Rails application this instruction is not called very much! So how would I handle all these calls to not render normally not as an escaped string?

like image 284
wael34218 Avatar asked Nov 03 '10 13:11

wael34218


1 Answers

Use <%= raw bla %> in inside the partial file.

  • http://github.com/rails/rails/blob/3270c58ebb3143b3ab3b349fe339cdd4587468ee/actionpack/lib/action_view/helpers/raw_output_helper.rb#L13

Rails 3 automatically makes everything safe. You need to put raw to escape the behavior. That also means you don't have to use h() method to make your string safe any more.

like image 187
TK. Avatar answered Oct 18 '22 05:10

TK.