基本上,我在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>
这给了我一个带有typeahead的工作表格框。但是,我希望能够在best_in_place中包含此类似
的内容<%= best_in_place @student, :education %>
这样用户只有在点击文本时才会看到预先输入的表单,点击该框或点击后输入选择将存储在数据库中。
有一种相当简单的方法吗?
答案 0 :(得分: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"]' %>
希望这有帮助!