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...

enter image description here

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.na‌​me}</a>".html_safe 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -