我期待在表单标签作为此类链接:在表单标签中加入链接?
<%= form.check_box 'eula' %>
<%= form.label 'eula', "I agree to the <a href='#' id='eula-link'>EULA</a>", class: 'label-checkbox' %>
Rails的写入HTML出来,因为它也许应该,但我将如何做到这一点?点击EULA打开一个JS弹出窗口。我想在那里嵌入一个link_to?
我期待在表单标签作为此类链接:在表单标签中加入链接?
<%= form.check_box 'eula' %>
<%= form.label 'eula', "I agree to the <a href='#' id='eula-link'>EULA</a>", class: 'label-checkbox' %>
Rails的写入HTML出来,因为它也许应该,但我将如何做到这一点?点击EULA打开一个JS弹出窗口。我想在那里嵌入一个link_to?
使用html_safe
用括号将呈现HTML,像这样:
<%= f.input :eula, :as => :boolean, label: ("I agree to the #{link_to 'Terms of Service', terms_path}.").html_safe %>
我相信你应该使用'sanitize'而不是'html_safe' – mecampbellsoup
你会如何在'link_to'中添加一个FontAwesome图标? – bcackerman
'label:sanitize(“我同意#{link_to((fa_icon('check')+'Terms and Conditions'),terms_and_conditions_path,target:'_blank')}。”,tags:%w(ai),属性:%w(href目标类))' – blnc
试试 “我同意#{的link_to '最终用户许可协议',#:ID => 'EULA链接'}”
不行的,还是非转义 –
假设你正在使用的香草轨形成助手,你可以这样做:
f.label :eula do
'I agree to the #{link_to("EULA", "#")}'
end
来源:http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-label
19种方式尝试,无论是超链接编码或html_safe替换连字符在URL?
这对我来说
<%= f.label :cookies do
"Do you agree to our #{link_to('Cookies Policy', 'http://www.your-url.co.uk/privacypolicy')}".html_safe
end %>
具体使用的“和”出现显著什么工作。
从简森按钮事件答案近为我工作,但需要改变在放置一个括号接近加载没有错误
对我来说,下面解决它。请注意在'饼干政策'这里,而不是在链接路径本身之后的关闭括号。
<%= f.label :cookies do
"Do you agree to our #{link_to('Cookies Policy'), 'http://www.your- url.co.uk/privacypolicy'}".html_safe
end %>
你只需要使用'link_to'辅助形式标签字符串,http://apidock.com/rails/ActionView/Helpers/UrlHelper/link_to – Norto23