【问题标题】:Drop down menu in Ruby on rails form_for with bootstrap带有引导程序的 Ruby on rails form_for 中的下拉菜单
【发布时间】:2015-09-12 23:53:34
【问题描述】:

我正在尝试在我的 ruby​​ on rails 应用程序中创建一个下拉菜单。我已经能够创建下拉菜单,但是我无法使用 Bootstrap 的样式。截至目前,它只是创建一个默认下拉菜单。

<%= form_for(@beverage, :html => {:class => "form-signin"}) do |f| %>
<div class="dropdown">
        <%= f.collection_select :status, Beverage::STATUS, :to_s, :to_s, :status =>true ,:class => "dropdown-menu"%>
</div>

在我的饮料模型中,我将STATUS 定义为

STATUS = ['hot', 'cold']

有没有办法将选中的值设置为 :status 中的值?

【问题讨论】:

    标签: html ruby-on-rails twitter-bootstrap


    【解决方案1】:

    我觉得你可能需要在添加类的时候用括号,不然就不行了,像这样:

    { :class => "dropdown-menu" } 
    

    collection_select 有这个参数:

    collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {})
    

    并且在实例对象上调用 method 返回的值将被选中..也许您的方法返回 nil..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      • 2014-08-04
      • 1970-01-01
      • 2021-07-27
      • 2013-03-28
      • 1970-01-01
      相关资源
      最近更新 更多