sách gpt4 ai đã đi

ruby-on-rails - Rails 中的 f.select 不应用 Bootstrap

In lại 作者:行者123 更新时间:2023-12-03 00:53:30 26 4
mua khóa gpt4 Nike

我在 Rails 表单中有以下选择元素:

<%= f.select :customer_type, options_for_select(["Retail","Contractor","Dealer"]), class: "form-control" %>

有谁知道为什么 Bootstrap 类:“form-control”不渲染?

我猜我的语法是错误的。任何帮助表示赞赏。

1 Câu trả lời

Per the documentation ,lựa chọn 的方法签名是:

select(object, method, choices, options = {}, html_options = {})

html_options 是您的 HTML 属性选项(如 :class)应该出现的位置,位于 tùy chọn 之后,但您省略了 tùy chọn và sẽ html_options Địa điểm choices 之后。试试这个:

<%= f.select :customer_type, options_for_select(["Retail","Contractor","Dealer"]), {}, class: "form-control" %>

附注如果你想知道为什么方法签名指定了 sự vật,但在实际使用中我们从不传递 sự vật(phương pháp 总是在前面),这是因为我们实际上并没有直接调用这个方法。当我们在 form_for block 内调用 f.select(...) 时,Rails 会调用 select(f.object, ...) for我们。

关于ruby-on-rails - Rails 中的 f.select 不应用 Bootstrap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25296145/

26 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com