Ruby on rails 使用haml在formtastic中添加指向标签/提示的链接

Ruby on rails 使用haml在formtastic中添加指向标签/提示的链接,ruby-on-rails,haml,formtastic,Ruby On Rails,Haml,Formtastic,我正在尝试使用haml在formtastic中添加一个到复选框的链接。formtastic在解析标签或提示时,似乎会从文本中删除所有ruby/haml/html语法 也就是说,这不起作用: = f.input :terms, label: '=link_to \'Here\', path_to_link', hint: '=link_to \'Other Place\', path_to_other_link', as: :boolean 除了在这个输入之外写另一个div之外,还有什么其他的方

我正在尝试使用haml在formtastic中添加一个到复选框的链接。formtastic在解析标签或提示时,似乎会从文本中删除所有ruby/haml/html语法

也就是说,这不起作用:

= f.input :terms, label: '=link_to \'Here\', path_to_link', hint: '=link_to \'Other Place\', path_to_other_link', as: :boolean

除了在这个输入之外写另一个div之外,还有什么其他的方法吗?还是我完全错了?我是rails/haml/formtastic noob

如果您使用'作为字符串引号,基本上就是告诉ruby不要解析该内容

请尝试以下方法:

= f.input :terms, label: link_to('Here', path_to_link), hint: link_to('Other place', path_to_other_link), as: :boolean

如果将传递给
标签:
提示:
的字符串标记为HTML安全,则Haml不会将其转义

= f.input :terms,
  label: "Please accept our ".html_safe + link_to('Terms and Conditions', path_to_link)

在您的formtastic初始值设定项中,尝试了19种方法,可以对超链接进行编码,也可以用html安全替换url中的连字符

这就是我的工作

<%= f.label :cookies do
  "Do you agree to our #{link_to('Cookies Policy', 'http://www.your-­url.co.uk/privacypolicy')}".html_safe
end %>


“and”的具体用法似乎很重要。

这是使用包含静态HTML内容的I18n本地化文件的最佳答案。但是,它无法解决@tessr在Formtastic标签或提示中嵌入HAML的问题。
<%= f.label :cookies do
  "Do you agree to our #{link_to('Cookies Policy', 'http://www.your-­url.co.uk/privacypolicy')}".html_safe
end %>