2012-06-17 92 views
12

我期待在表單標籤作爲此類鏈接:在表單標籤中加入鏈接?

<%= 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?

+0

你只需要使用'link_to'輔助形式標籤字符串,http://apidock.com/rails/ActionView/Helpers/UrlHelper/link_to – Norto23

回答

18

使用html_safe用括號將呈現HTML,像這樣:

<%= f.input :eula, :as => :boolean, label: ("I agree to the #{link_to 'Terms of Service', terms_path}.").html_safe %> 
+1

我相信你應該使用'sanitize'而不是'html_safe' – mecampbellsoup

+1

你會如何在'link_to'中添加一個FontAwesome圖標? – bcackerman

+0

'label:sanitize(「我同意#{link_to((fa_icon('check')+'Terms and Conditions'),terms_and_conditions_path,target:'_blank')}。」,tags:%w(ai),屬性:%w(href目標類))' – blnc

0

試試 「我同意#{的link_to '最終用戶許可協議',#:ID => 'EULA鏈接'}」

+3

不行的,還是非轉義 –

1

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 %> 

具體使用的「和」出現顯著什麼工作。

1

從簡森按鈕事件答案爲我工作,但需要改變在放置一個括號接近加載沒有錯誤

對我來說,下面解決它。請注意在'餅乾政策'這裏,而不是在鏈接路徑本身之後的關閉括號。

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