module DatashiftJourney::FormMixin
Collection of tools to support the Forms
Attributes
journey_plan[R]
redirection_url[RW]
Public Instance Methods
form_definition()
click to toggle source
# File lib/datashift_journey/form_mixin.rb, line 28 def form_definition # In this situation self is the class of the including form eg PaymentForm, AddressFrom begin @form_definition ||= DatashiftJourney::Collector::FormDefinition.find_or_create_by(klass: self.name) rescue Rails.logger.error "Could not find or create FormDefinition [#{x}]" nil end end
journey_plan_form_field(name:, category:)
click to toggle source
Form helper to add fields inside a class definition
N.B Currently this will create a permanent entry in the DB, so removing this code will not remove the Field - must be deleted from DB
Usage
journey_plan_form_field name: :model_uri, category: :string journey_plan_form_field name: :run_time, category: :select_option journey_plan_form_field name: :memory, category: :number
# File lib/datashift_journey/form_mixin.rb, line 49 def journey_plan_form_field(name:, category:) begin DatashiftJourney::Collector::FormField.find_or_create_by!(form_definition: form_definition, name: name, category: category) rescue => x Rails.logger.error "Could not find or create FormField [#{x}]" nil end end
redirect?()
click to toggle source
# File lib/datashift_journey/form_mixin.rb, line 21 def redirect? Rails.logger.debug "Checking for REDIRECTION - [#{redirection_url}]" !redirection_url.nil? end
validate(params)
click to toggle source
Calls superclass method
# File lib/datashift_journey/form_mixin.rb, line 16 def validate(params) Rails.logger.debug "VALIDATING #{model.inspect} - Params - #{form_params(params)}" super form_params(params) end
Protected Instance Methods
form_params(params)
click to toggle source
# File lib/datashift_journey/form_mixin.rb, line 61 def form_params(params) params.fetch(params_key, {}) end
logger()
click to toggle source
# File lib/datashift_journey/form_mixin.rb, line 65 def logger Rails.logger end