I am a novice ruby developer.
<%= select_tag "access", "<option>Read</option><option>Write</option>".html_safe, multiple: true, class: 'form_input'%>
'html_safe' <<< what is used for?
I am a novice ruby developer.
<%= select_tag "access", "<option>Read</option><option>Write</option>".html_safe, multiple: true, class: 'form_input'%>
'html_safe' <<< what is used for?
html_safe is here to actually use the HTML tags inside the string as actual HTML.
For example:
"<p>Hello</p>".html_safe will actually print a HTML tag p wrapping the string "Hello""<p>Hello</p>" will output "<p>Hello</p>" inside the page (<p> tags not being evaluated as HTML)In your case, "<option>Read</option><option>Write</option>".html_safe will output two option HTML tags with "Read" and "Write".
A better way to generate options for a select is ... options_for_select:
select_tag 'access', options_for_select(['Read', 'Write'])
` becomes `<p>`.
– tadman Sep 12 '14 at 17:44