Module: Librails::ApplicationHelper

Defined in:
app/helpers/librails/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#bootstrap_class_for(flash_type) ⇒ Object



4
5
6
# File 'app/helpers/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

#flash_messages(opts = {}) ⇒ Object

noinspection RubyUnusedLocalVariable



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

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



25
26
27
28
29
30
# File 'app/helpers/librails/application_helper.rb', line 25

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