I'm trying to add a link to a checkbox in formtastic, using haml. It looks like formtastic removes all ruby/haml/html syntax from the text for the label or hint when it parses it.
That is, this doesn't work:
= f.input :terms, label: '=link_to \'Here\', path_to_link', hint: '=link_to \'Other Place\', path_to_other_link', as: :boolean
Is there anything that will other than writing another div outside of this input? Or am I going about this all wrong? I'm a rails/haml/formtastic noob.
if you use ' for string quotation, you're basically telling ruby not to parse that content.
try something like this instead:
= f.input :terms, label: link_to('Here', path_to_link), hint: link_to('Other place', path_to_other_link), as: :boolean
Formtastic::FormBuilder.escape_html_entities_in_hints_and_labels = false
在您的formtastic初始化程序中
19 ways tried, with either the hyperlink being encoded or html_safe replacing hyphens in the url ???
This is what worked for me
<%= f.label :cookies do
"Do you agree to our #{link_to('Cookies Policy', 'http://www.your-url.co.uk/privacypolicy')}".html_safe
end %>
The specific use of " and ' appears significant.
If you mark the string passed to label:
or hint:
as HTML safe then Haml doesn't escape it.
= f.input :terms,
label: "Please accept our ".html_safe + link_to('Terms and Conditions', path_to_link)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.