我们如何使用 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)"} ) %>
关于javascript - 如何使用 f.select 获取静态哈希值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39138297/