简体   繁体   English

带有引导程序的Ruby on Rails form_for下拉菜单

[英]Drop down menu in Ruby on rails form_for with bootstrap

I am trying to create a drop down in my ruby on rails application. 我试图在我的ruby on rails应用程序中创建一个下拉列表。 I have been able to create the drop down however I am not able to use the styling of Bootstrap. 我已经能够创建下拉列表,但是我无法使用Bootstrap的样式。 It is just creating a default dropdown as of now. 到目前为止,它只是创建一个默认下拉列表。

<%= 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>

In my beverage model I defined STATUS as 在我的饮料模型中,我将STATUS定义为

STATUS = ['hot', 'cold']

Is there a way to set the selected value as the value in :status? 有没有一种方法可以将所选值设置为:status中的值?

I think you may need to use brackets when adding a class, otherwise it won't work, something like this: 我认为您在添加类时可能需要使用方括号,否则它将无法正常工作,如下所示:

{ :class => "dropdown-menu" } 

collection_select has this parameters: collection_select具有以下参数:

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

And the value returned from calling method on the instance object will be selected.. maybe your method is returning nil.. 并且从实例对象上的调用方法返回的值将被选择..也许您的方法返回nil ..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM