我创建了一个名为'内部版本的控制器。
我想检查多选对象是否至少包含一个选项。
在我的控制器中我有:
class InternalReleasesController < ApplicationController
def show
if params[:run].nil?
logger.error "Attempt to get trend result without going through the internal_releases_trend_selection_url"
flash[:no_arguments] = 'You have tried accessing trend results without selecting parameters.'
redirect_to internal_releases_trend_selection_url
else
all_options = Array.new(params[:run][:category_id])
missing_selections = validate_arguments params[:run]
all_options = Array.[]params[:run][:category_id]
logger.debug "all_options is: #{all_options.class}"
end
end
end
我创建了一个简单的帮助方法:
module InternalReleasesHelper
def validate_arguments multiselect_hash
answer = Array.new
multiselect_arr.each do |key, val_arr|
if val_arr.length==1 # therefore, no selection made in this multiselect- the first arg will always be ""
answer << key
end
end
answer
end
end
出于某种原因,我得到了:
undefined method `validate_arguments' for #<InternalReleasesController:0x007faf08bf9f78>
可能导致这种情况的原因是什么?
答案 0 :(得分:3)
将帮助程序模块 InternalReleasesHelper 包含在 InternalReleasesController 类
中class InternalReleasesController
include InternalReleasesHelper
end
答案 1 :(得分:1)
Helper的方法默认情况下只在Views中可用,因此你应该将你的助手包含在控制器中:
浏览internal_releases_controller.rb文件并插入以下内容:
include InternalReleasesHelper