【问题标题】:Is it possible to use best_in_place with typeahead from twitter bootstrap?是否可以将 best_in_place 与 twitter bootstrap 中的 typeahead 一起使用?
【发布时间】:2012-03-18 17:53:35
【问题描述】:

基本上,我在我的 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 %>

这样用户只有在点击文本时才能看到预先输入的表单,并且在离开框或点击回车时,选择会存储在数据库中。

有没有相当简单的方法可以做到这一点?

【问题讨论】:

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1 ruby-on-rails-plugins twitter-bootstrap


【解决方案1】:

在任何 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"]' %>

希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多