5

基本上,我在我的rails webapp中使用best_in_place來讓用戶編輯他們的個人資料信息。問題是,我想用戶與預輸入形式呈現某些條目。這裏就是我的工作:是否有可能使用best_in_place typeahead從twitter引導?

<p>College/University: <input type="text" class="span3" style="margin: 0 auto;" data-provide="typeahead" data-items="8" data-source='["University of Pennsylvania","Harvard","Yale","Princeton","Cornell","Brown","Columbia","Dartmouth"]'></p> 

這讓我有預輸入工作表格框。不過,我希望能夠用的東西來包裝這個在best_in_place像

<%= best_in_place @student, :education %> 

,使用戶只能看到預輸入形式,當他們點擊文本,並在從盒子馬上點擊或按下回車鍵的選擇存儲在數據庫中。

有沒有一個相當簡單的方法來做到這一點?

+1

參考http://stackoverflow.com/questions/14796415/how-to-use-best-in-place-with-twitter-bootstrap – 2013-10-09 11:14:13

回答

0

在任何Ruby on rails輔助方法(例如best_in_place)上,您只需添加:html_attrs選項即可。這裏是你的樣子:

<%= best_in_place @student, :education, :type=> :input, 
    :html_attrs => {:'data-provide' => "typeahead", // Any other attributes 
        :'data-source' => '["University of Pennsylvania","Harvard","Yale","Princeton","Cornell","Brown","Columbia","Dartmouth"]' %> 

希望這會有所幫助!

相關問題