ruby-on-rails - 使用布尔值设置 Rails 选择框的样式
问题描述
我试图在 Stack 上找到我要查找的内容,但无济于事,我试图将自定义样式类添加到 rails 中的选择表单字段,但我正在删除..有人可以帮帮我吗?
<%= f.select(:allow_profile_update_no_pw, options_for_select([['Active', true], ['Inactive', false]], {:selected => current_user.allow_profile_update_no_pw, :class => "someClass"}),:prompt => "Select") %>
这是我将它放在任何 {} 中时遇到的错误
wrong number of arguments (given 3, expected 1..2)
移出那些我无法得到任何结果的人。
解决方案
select
方法是这样定义的
select(object, method, choices = nil, options = {}, html_options = {}, &block)
在您的情况下,您需要将class
键值对移动到下一个参数,即 under html_options
,以及其他一些修复,它应该看起来像这样
<%= f.select :allow_profile_update_no_pw, options_for_select([['Active', true], ['Inactive', false]], current_user.allow_profile_update_no_pw),{ :prompt => "Select"}, { :class => "someClass" } %>
https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-select
推荐阅读
- reactjs - Is there anyway to dynamically add a child to a JSX element?
- debugging - Intellij: how to open a library java source and set a breakpoint for debugging?
- java - How to make IntelliJ color preview recognize a custom Color class?
- c# - How to return value of items in Listbox to Textbox
- excel - 如何格式化此 VBA 电子邮件
- python - Python DataFrame 选择行 3 年
- python - urllib3 和 curl 不适用于某些网站,但浏览器可以使用
- python - 如何在不使用 for 循环的情况下检索具有明确列名的数据框中的每一行并写入“Hi 5”?
- java - 如何将多部分响应作为流读取和解析?
- python - 从内存中删除某些变量未初始化的特定变量(尝试除外)