gpt4 book ai didi

css - 将 CSS 类添加到 select_month

转载 作者:数据小太阳 更新时间:2023-10-29 07:47:42 25 4
gpt4 key购买 nike

我有以下 select_month 助手。我想添加一个 class,但它没有生成 HTML

select_month(Date.today,
:add_month_numbers => true,
:html => { :class => 'col-xs-3' }
)

我也按照一些解决方案的建议尝试过使用哈希,但出现语法错误:

select_month(Date.today,
:add_month_numbers => true,
{ :class => 'col-xs-3' }
)

和:

select_month(Date.today,
:add_month_numbers => true,
:class => 'col-xs-3'
)

不确定我是否真正了解何时以及如何使用散列对其进行格式化。

最佳答案

由于第二个和第三个参数都是哈希值,所以需要将第二个参数用花括号括起来

select_month(Date.today,
{:add_month_numbers => true},
:class => '.col-xs-3'
)

您只能在给定函数的最后一个散列参数上省略大括号。 select_month 的定义如下:

select_month(date, options = {}, html_options = {}) public

如您所见,optionshtml_options 都接受哈希值。为了避免 Ruby 混淆,只需将第二个(或两个)参数放在花括号内。

关于css - 将 CSS 类添加到 select_month,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33016571/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com