html_safe on whole html code block in rails

469 views Asked by At

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 :)

1

There are 1 answers

2
pdobb On BEST ANSWER

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")