Preventing HTML character entities in locale files from getting munged by Rails3 xss protection

后端 未结 5 1276
遇见更好的自我
遇见更好的自我 2021-02-03 23:58

We\'re building an app, our first using Rails 3, and we\'re having to build I18n in from the outset. Being perfectionists, we want real typography to be used in our views: dashe

5条回答
  •  抹茶落季
    2021-02-04 00:25

    If you don't wanna expose to the possibility of a mistake by simple adding .html_safe (through alias_method_chain or w/e) to everything, the best solution is simply to use it whenever it is necessary.

    In our site we use markup language to get HTML output from i18n locale files, since who translates those files are not developers, just translators.

    If it is only on a few places that you need your HTML to really be HTML, use .html_safe

    t('views.signup.organisation_details').html_safe
    

    The simple markup language we have works pretty well for us, but that is really case-specific :)

提交回复
热议问题