Module: Effective::FlashMessages
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/controllers/concerns/effective/flash_messages.rb
Instance Method Summary collapse
-
#flash_danger(resource, action = nil, e: nil, name: nil) ⇒ Object
flash.now = flash_danger(@post).
-
#flash_errors(resource, e: nil) ⇒ Object
flash.now = “Unable to accept: #flash_errors(@post)”.
-
#flash_success(resource, action = nil, name: nil) ⇒ Object
flash = flash_success(@post).
Instance Method Details
#flash_danger(resource, action = nil, e: nil, name: nil) ⇒ Object
flash.now = flash_danger(@post)
16 17 18 19 20 21 22 23 24 |
# File 'app/controllers/concerns/effective/flash_messages.rb', line 16 def flash_danger(resource, action = nil, e: nil, name: nil) raise 'expected an ActiveRecord resource' unless resource.respond_to?(:errors) && (name || resource.class.respond_to?(:model_name)) action ||= resource.respond_to?(:new_record?) ? (resource.new_record? ? :create : :update) : :save name ||= resource.class.model_name.human = flash_errors(resource, e: e) ["Unable to #{action} #{name.to_s.downcase}", (": #{}." if )].compact.join.html_safe end |
#flash_errors(resource, e: nil) ⇒ Object
flash.now = “Unable to accept: #flash_errors(@post)”
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/concerns/effective/flash_messages.rb', line 27 def flash_errors(resource, e: nil) raise 'expected an ActiveRecord resource' unless resource.respond_to?(:errors) = resource.errors.map do |attribute, | if [0] == [0].upcase # If the error begins with a capital letter elsif attribute == :base "#{resource.class.model_name.human.downcase} #{}" elsif attribute.to_s.end_with?('_ids') "#{resource.class.human_attribute_name(attribute.to_s[0..-5].pluralize).downcase} #{}" else "#{resource.class.human_attribute_name(attribute).downcase} #{}" end end << e. if .blank? && e && e.respond_to?(:message) .to_sentence.presence end |
#flash_success(resource, action = nil, name: nil) ⇒ Object
flash = flash_success(@post)
6 7 8 9 10 11 12 13 |
# File 'app/controllers/concerns/effective/flash_messages.rb', line 6 def flash_success(resource, action = nil, name: nil) raise 'expected an ActiveRecord resource' unless (name || resource.class.respond_to?(:model_name)) action ||= :save name ||= resource.class.model_name.human "#{name.to_s.titleize} was successfully #{action}#{(action.to_s == 'submit' ? 't' : '')}#{(action.to_s.end_with?('e') ? 'd' : 'ed')}" end |