2016-09-26 30 views
1

我使用simple_form Rails中4,和我使用的輸入,我再傳給數據屬性,像這樣:Rails中4使用simple_form,試圖通過數據屬性的input_field

<%= f.input :url, :input_html => {"data-toggle" => "tooltip", :title => "My tooltip"} %> 

和它的工作如預期,如創建標籤:

<input data-toggle="tooltip" data-original-title="My tooltip"> 

但是現在,我需要使用simple_form的input_field所以我可以在顯示更多的控制權,但它似乎並沒有接受input_html說法。我的代碼如下所示:

<%= f.input_field :url, :input_html => {"data-toggle" => "tooltip", :title => "My tooltip"} %> 

,並導致:

<input html="{:data=>{&quot;data-toggle&quot;=>&quot;tooltip&quot;, :title=>&quot;My tooltip&quot;}}"> 

,這顯然是不理想的(我剝奪其他不相關的屬性和特性來簡化)。關於如何使這項工作的任何想法?

回答

2

查看SimpleForm::FormBuilder#input_field的代碼,看起來所有傳入的選項都被視爲在:input_html之下。

嘗試刪除:input_html而直接傳遞的選項:

<%= f.input_field :url, "data-toggle" => "tooltip", :title => "My tooltip" %> 
+1

是的,這工作。我確實讀過代碼,但還是不太清楚應該如何傳遞這些屬性(我試過':data-toggle =>「tooltip」',這是行不通的。) – Wemmick

相關問題