传递grouped_options_for_select以在 Rails 5.0.6 中选择帮助程序



我的select不起作用并抛出此错误:

undefined local variable or method `marketplace_listing' 
for #<#<Class:0x007fe2a496e950>:0x007fe2920faf38>

我把这个select放在一个视图上。

<%= f.select :marketplace, grouped_options_for_select(marketplace_listing),
{}, {prompt: "Select your Marketplace", 
class: "icon_prefix input-field input-bottom-fixed down"}, required: true %>

marketplace_listing是我定义的帮助程序方法,如下所示:

module MarketplaceHelper
   def marketplace_listing
    {
      "North America" => [
        ['Canada', 'A2EUQ1WTGCTBG2'],
        ['Mexico', 'A1AM78C64UM0Y8'],
        ['United States', 'ATVPDKIKX0DER']
      ],
      "Europe" => [
        ['France', 'A13V1IB3VIYZZH'],
        ['Germany', 'A1PA6795UKMFR9'],
        ['Italy', 'APJ6JRA9NG5V4'],
        ['Spain', 'A1RKKUPIHCS9HS'],
        ['United Kingdom', 'A1F83G8C2ARO7P']
      ]
    }
  end      
end

我哪里做错了?

将帮助程序包含在相应的控制器中

class YourController < ApplicationController
  helper MarketplaceHelper
  ...
end

最新更新