Module: DatashiftJourney::ApplicationHelper
- Defined in:
- app/helpers/datashift_journey/application_helper.rb
Instance Method Summary collapse
- #all_errors(record) ⇒ Object
- #error_link_id(attribute) ⇒ Object
- #friendly_date(date) ⇒ Object
-
#journey_plan_partial?(state) ⇒ Boolean
Returns true if ‘_state’ partial exists in configured location (Configuration.partial_location).
-
#journey_plan_partial_location(state) ⇒ Object
helper to return the location of a partial for a particular state.
-
#render_if_exists(state, *args) ⇒ Object
This is the main hook to insert a States partial view into the main Form.
Instance Method Details
#all_errors(record) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'app/helpers/datashift_journey/application_helper.rb', line 34 def all_errors(record) record.class.reflect_on_all_associations.each do |a| assoc = @journey_plan.send(a.name) next unless assoc && assoc.respond_to?(:errors) assoc.errors..each do || "<li><a href='<%= message %>'></a></li>" end end end |
#error_link_id(attribute) ⇒ Object
27 28 29 30 31 32 |
# File 'app/helpers/datashift_journey/application_helper.rb', line 27 def error_link_id(attribute) # with nested attributes can get full path e.g applicant_contact.full_name # we only want the last field field = attribute.to_s.split(/\./).last "form_group_#{field}" end |
#friendly_date(date) ⇒ Object
44 45 46 47 |
# File 'app/helpers/datashift_journey/application_helper.rb', line 44 def friendly_date(date) formatted_date = date && l(date.to_date, format: :long) formatted_date || '' end |
#journey_plan_partial?(state) ⇒ Boolean
Returns true if ‘_state’ partial exists in configured location (Configuration.partial_location)
13 14 15 16 17 18 19 |
# File 'app/helpers/datashift_journey/application_helper.rb', line 13 def journey_plan_partial?(state) return true if lookup_context.exists?(state, [DatashiftJourney::Configuration.call.partial_location], true) Rails.logger.warn("DSJ - No partial found for [#{state}] in path(s) [#{lookup_context.prefixes.inspect}]") false end |
#journey_plan_partial_location(state) ⇒ Object
helper to return the location of a partial for a particular state
22 23 24 25 |
# File 'app/helpers/datashift_journey/application_helper.rb', line 22 def journey_plan_partial_location(state) Rails.logger.debug("DatashiftJourney RENDER #{DatashiftJourney::Configuration.call.partial_location}/#{state}}") File.join(DatashiftJourney::Configuration.call.partial_location.to_s, state) end |
#render_if_exists(state, *args) ⇒ Object
This is the main hook to insert a States partial view into the main Form
5 6 7 8 9 |
# File 'app/helpers/datashift_journey/application_helper.rb', line 5 def render_if_exists(state, *args) lookup_context.prefixes.prepend DatashiftJourney::Configuration.call.partial_location render(state, *args) if lookup_context.exists?(state, lookup_context.prefixes, true) end |