Module: Librails::ApplicationHelper

Defined in:
lib/librails/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#bootstrap_class_for(flash_type) ⇒ Object



4
5
6
# File 'lib/librails/application_helper.rb', line 4

def bootstrap_class_for(flash_type)
  { success: "alert-success", error: "alert-danger", alert: "alert-warning", notice: "alert-info" }[flash_type.to_sym] || flash_type.to_s
end

#bs5_flash_messages(opts = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/librails/application_helper.rb', line 24

def bs5_flash_messages(opts = {})
  # https://github.com/plataformatec/devise/issues/1777
  # deviseが:timeoutにtrueをぶちこんでくるのでそれを除外する
  flash.each do |msg_type, message|
    next if msg_type == :timedout
    concat((:div, message, class: "alert #{bootstrap_class_for(msg_type)} alert-dismissible", role: 'alert') do
      concat((:button, class: 'btn-close', data: { bs_dismiss: 'alert' }, aria_label: 'Close') do
      end)
      concat message
    end)
  end
  nil
end

#flash_messages(opts = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/librails/application_helper.rb', line 8

def flash_messages(opts = {})
  # https://github.com/plataformatec/devise/issues/1777
  # deviseが:timeoutにtrueをぶちこんでくるのでそれを除外する
  flash.each do |msg_type, message|
    next if msg_type == :timedout
    concat((:div, message, class: "alert #{bootstrap_class_for(msg_type)} alert-dismissible", role: 'alert') do
             concat((:button, class: 'close', data: { dismiss: 'alert' }) do
                      concat (:span, '×'.html_safe, 'aria-hidden' => true)
                      concat (:span, 'Close', class: 'sr-only')
                    end)
             concat message
           end)
  end
  nil
end

#ransack_value(params, value_param, query_param = 'q') ⇒ Object



37
38
39
40
41
42
# File 'lib/librails/application_helper.rb', line 37

def ransack_value(params, value_param, query_param = 'q')
  q = params[query_param]
  return nil unless q
  return nil unless q.kind_of?(ActionController::Parameters)
  q[value_param]
end