基本上,我在我的 rails webapp 中使用 best_in_place 让用户就地编辑他们的个人资料信息。问题是,我希望为用户提供某些条目的预输入表单。这就是我正在使用的内容:
<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 %>
这样用户只有在单击文本时才能看到预先输入的表单,并且在单击离开框或按 Enter 时,选择将存储在数据库中。
有没有一种相当简单的方法来做到这一点?
最佳答案
在任何 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"]' %>
希望这可以帮助!
关于ruby-on-rails - 是否可以将 best_in_place 与 twitter bootstrap 中的 typeahead 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9760698/