Calling 'sanitize' on collection_radio_buttons text_method

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(sub sup))

``

Any idea? Thank you.

I meant how to change or customise a radio button label text so that to be able to display Math and chemistry formulas using

``

and

``

tags.

I figured out how to achieve that:

<%= f.collection_radio_buttons :name, [[true, ‘H2O’] ,[false, ‘SO2’]], :first, :last do |b| %>
<%= b.label {b.radio_button + sanitize(b.text, tags: %w(sub sup))}%>
<%end%>

``

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

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

-Rob

Yes, Rod, thank you for the idea. I knew that, it would work. I don’t want to mess the View stuff with the the Model ones. The input will be done by admins only (back office), so this kind of GUI will have no danger and will make it possibe for them to encode formulas and a final user will see the desired result as needed.

Regards