ruby on rails - How to escape HTML tags in errors in simple_form -
i'm using rails 3.2.22 , simple_form 2.1.3
some of our fields have duplicate checking , error includes link duplicated record (so user can check if it's name that's duplicated, or if don't need create record).
however, we've switched customised form builder simple form, , these error messages escaped, displaying escaped error.
i reproduced issue in a minimal app:
in doohickey model:
validate :unique_name_validation def unique_name_validation other_doohickey = doohickey.find_by_name(name) if other_doohickey errors.add( :name, "this name taken <a href='/doohickey/#{other_doohickey.id}'>#{other_doohickey.name}</a>" ) end end
in ui:
<%= simple_form_for @doohickey |form| %> <%= form.input :name %> <%= form.button :submit %> <% end %>
the ui shows html on page itself...
there's configuration in /config/initializers.rb, haven't found way there turn off escaping.
how can display links errors using simple form?
bearing in mind content won't never nil, can use html_safe
, like:
"this name taken <a href='/doohickey/#{other_doohickey.id}'>#{other_doohickey.name}</a>".html_safe
Comments
Post a Comment