From e85d846c08779e8f3a262a244fedab1ca6c1986a Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 10 Feb 2015 14:55:04 +0200 Subject: [PATCH] Allow blank for requires helper --- app/controllers/epp_controller.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/epp_controller.rb b/app/controllers/epp_controller.rb index 28eff040f..4749c1ff0 100644 --- a/app/controllers/epp_controller.rb +++ b/app/controllers/epp_controller.rb @@ -84,12 +84,19 @@ class EppController < ApplicationController # TODO: Add possibility to pass validations / options in the method def requires(*selectors) + options = selectors.extract_options! + allow_blank = options[:allow_blank] ||= false # allow_blank is false by default + el, missing = nil, nil selectors.each do |selector| full_selector = [@prefix, selector].compact.join(' ') el = params[:parsed_frame].css(full_selector).first - missing = el.nil? + if allow_blank + missing = el.nil? + else + missing = el.present? ? el.text.blank? : true + end epp_errors << { code: '2003', msg: I18n.t('errors.messages.required_parameter_missing', key: full_selector)