0

我对白名单一无所知。我在哪里放

if %w(some valid input).include?(params[:input])
  # proceed with action
else
  # not in whitelist, throw error
end

以及如何从表单的提交操作中调用它?

4

1 回答 1

3

我真的不知道您期望什么,但这可能是before_filter.

它会让你的控制器保持干燥。见文档

在你的控制器中,试试这个:

before_filter :check_params, :only => [:index, :whatever_action_name]

def check_params
  raise ActionController::RoutingError.new('Missing params') unless %w(some valid input).include?(params[:input])
end
于 2011-07-10T20:49:58.480 回答