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

标签 javascript html css ruby-on-rails

我们如何使用 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/

相关文章:

javascript - 当我单击“'"更多”按钮时如何将 div 高度属性更改为自动

css - 如何设置图像编辑页面

javascript - 有 Firebug 控制台 -vsdoc.js 吗?

html - 如何使文档正文中的CSS样式仅特定于div

css - 如何在同一行上将文本左对齐和图像右对齐?

html - 固定表格td的宽高

javascript - 在 mmenu 中选择所有直接父列表条目

javascript - 如何根据选择隐藏和显示 HTML 中的字段

javascript - 无法使用 Google 距离矩阵读取未定义的属性 'text'

javascript - 数据表行数不适用于搜索结果