gpt4 book ai didi

javascript - 如何使用 f.select 获取静态哈希值?

转载 作者:行者123 更新时间:2023-11-28 05:19:27 25 4
gpt4 key购买 nike

我们如何使用 f.select 标签来收集静态哈希值

class ReceiptPrinter
RECEIPT_PRINTER_TYPES ={
0=> "Normal",
1=> "Dot Matrix",
2=> "Thermal",
}

def initialize(options={})
@receipt_printer_type=options[:receipt_printer_type] || DEFAULT_VALUES[:ReceiptPrinterType]
@receipt_printer_header_height=options[:receipt_printer_header_height]|| DEFAULT_VALUES[:ReceiptPrinterHeaderHeight]
@receipt_printer_header_type=options[:receipt_printer_header_type]|| DEFAULT_VALUES[:ReceiptPrinterHeaderType]
@receipt_printer_template=options[:receipt_printer_template]|| DEFAULT_VALUES[:ReceiptPrinterTemplate]
# define_methods()
end
end

在我的 View 页面中我使用了选择选项

<% form_for @receipt_printer, :url => { :action => "fees_receipt_settings" } do |f| %>
<%= f.select("receipt_printer_template", @settings.map{| item| [item[0],item[1].to_i]},{},{:onchange => "set_template(this.value)"} ) %>
<% end %>

我得到错误的参数数量错误

最佳答案

你可以试试rails的options_for_select,

<%= f.select :receipt_printer_template",options_for_select(@settings.map{ |item| [item[0], item[1]],{},{:onchange => "set_template(this.value)"} ) %>

Here is the reference

关于javascript - 如何使用 f.select 获取静态哈希值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39138297/

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