Ruby on Rails Thursday, October 27, 2016


On 2016-Oct-27, at 08:26 , Serguei Cambour <s.cambour@gmail.com> wrote:

I figured out how to achieve that:

<%= f.collection_radio_buttons :name, [[true, 'H<sub>2</sub>O'] ,[false, 'SO<sub>2</sub>']],:first, :last do |b| %>
        <%= b.label {b.radio_button + sanitize(b.text, tags: %w(sub sup))}%>
  <%end%>

On Wednesday, 26 October 2016 12:45:48 UTC+2, Serguei Cambour wrote:
How is it possible to call sanitize on the below collection_radio_buttons method:

= f.collection_radio_buttons :answer_ids, @question.answers, :id



I tried as follows and it failed:

= f.collection_radio_buttons :answer_ids, @question.answers, :id, sanitize(:text, tags: %w(subsup))

Any idea? Thank you.


While I wouldn't normally suggest this for user-supplied data, you could change the Answer#text to return .sanitize'd strings:

class Answer

  include ActionView::Helpers::SanitizeHelper 
  def text
    sanitize(read_attribute(:text), tags: %w[sub sup])
  end

end

think that this will work, but I haven't tried it myself.

-Rob

No comments:

Post a Comment