1

i can't seem to find a way to escape whole html block, if it is even possible.

Here is what i am trying to do:

%table
  %tr
    %th{rowspan: "2"}= t("public.home.graphic_title_payment").html_safe
    %th.datefield{rowspan: "2"}= t("public.home.graphic_title_dates").html_safe
    %th{colspan: "3"}= t("public.home.graphic_title_pay_group").html_safe
    %th{rowspan: "2"}= t("public.home.graphic_title_unpaid").html_safe

Altho i dont like purring .html_safe at the end of every string. Is there a way i could maybe put some kind of indicator that all %tr needs to be html_safe??

Thanks :)

user2945241
  • 360
  • 5
  • 19

1 Answers1

1

Rails escapes ERB output by default. So the best thing would probably be to create a new helper method to run the I18n translation and mark it as safe. So perhaps:

# app/helpers/application_helper.rb
def st(translation)
  t(translation).html_safe
end

Then:

%th{rowspan: "2"}= st("public.home.graphic_title_payment")
pdobb
  • 17,688
  • 5
  • 59
  • 74
  • thx for answer, that is what i did almost instantly when i finished question :) but i still wanted to know if there is a way to do this for blocks... – user2945241 May 27 '14 at 12:57
  • You *could* do a whole block if you were producing the HTML as well inside of that block. Otherwise each ERB output into the HTML needs to be escaped. Also, it's a dangerous way of thinking to simply mark everything as safe so it's not supposed to be easy :) – pdobb May 27 '14 at 13:35