ruby-on-rails - 是否可以将 best_in_place 与 twitter bootstrap 中的 typeahead 一起使用?

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

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

相关文章:

ruby-on-rails - amazon-product-advertising-api gem + Rails 3

ruby-on-rails - 如何显示视频?

ruby-on-rails - 在 vps 托管上配置 Rails 服务器

ruby-on-rails - :through association 的 Rails where 子句

testing - 具有 https 约束的功能测试路由

ruby-on-rails - 通过 AJAX 创建表单时显示错误消息

ruby - Haml 语法错误 > 非法元素类和 ID 必须有值

ruby-on-rails-3 - 使用 RSpec 创建 rails 3 插件

ruby-on-rails-3.1 - 如何让 best_in_place 的 respond_with_bip 工作?

ruby-on-rails - 渲染部分 Assets