2016-09-30 55 views
0

我很新的rails,我試圖以某種方式添加button_to中button_to的所有屬性和類,因爲此刻它在我的實際按鈕上添加了一個銀色按鈕框,所以我沒有知道如何將上面的多個類實際組合在一起。如何將多個類和屬性添加到rails button_to?

<button class="class1" data-method="dl" data-option="dl" type="button" title="Dl"> 
     <span class="class2" data-placement="bottom" title="Dl"> 
       <span class="icon"> 
        <%= button_to proof_path(@param) %> 
       </span> 
     </span> 
    </button> 

link_to不起作用,因爲我希望實際的按鈕是可點擊的而不是文本。

有什麼建議嗎?

回答

0

可以傳遞的東西進入button_to在塊

前。

<%= button_to [:make_happy, @user] do %> 
    Make <strong><%= @user.name %></strong> happy 
<% end %> 

你可以把圖標,什麼不能在該塊...

裁判:Docs

+0

謝謝,這正是我解決這個問題的方法! – RushRed

0

您試圖將一個按鈕嵌入到無效的html按鈕中。第一步是隻使用一個按鈕。第二步是使用button_to來設置所有您需要的html屬性。

防爆

button_to("Button Text", proof_path(@param), {}, 
      data: {method: "dl, option: "dl"}, class: "class1") 
+0

謝謝,我不知道這一點,也採用了塊之後,使其更具可讀性,如在上面的答案中說明。 – RushRed

相關問題