belgoros
(belgoros)
October 26, 2016, 10:45am
1
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.
belgoros
(belgoros)
October 27, 2016, 10:54am
2
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.
belgoros
(belgoros)
October 27, 2016, 12:26pm
3
I figured out how to achieve that:
<%= f.collection_radio_buttons :name, [[true, ‘H2 O’] ,[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
belgoros
(belgoros)
October 28, 2016, 7:14am
5
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