在Rails 5中将类添加到bootstrap_form_for collection_select [英] Add class to bootstrap_form_for collection_select in Rails 5

查看:58
本文介绍了在Rails 5中将类添加到bootstrap_form_for collection_select的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用bootstrap_form_for创建表单并选择一个集合,我想在其中添加一个自定义类.我试过了,但这行不通:

I use bootstrap_form_for to create forms and have a collection select, where I want to add a custom class. I tried this, but this does not work:

<%= f.collection_select :location, Location.all, :id, :name, label: 'Location', :include_blank => ("Select..."), hide_label: true, :class => 'location' %>

有什么想法吗?

推荐答案

许多Rails助手使用多个哈希参数.

Many Rails helpers take multiple hash arguments.

这个collection_select方法的定义如下:

And the definition of this collection_select method looks like this:

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

因此您的选择字段将是:

So your select field will be:

<%= f.collection_select :location, Location.all, :id, :name,
    {label: 'Location', :include_blank => ("Select..."), hide_label: true}, {class: "location"} %>

这篇关于在Rails 5中将类添加到bootstrap_form_for collection_select的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆