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

时间:2018-01-30 22:33:25

标签: ruby-on-rails

我的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

我哪里出错了?

1 个答案:

答案 0 :(得分:2)

在适当的控制器中包含帮助程序

class YourController < ApplicationController
  helper MarketplaceHelper
  ...
end