Module: ActsAsRailable::ViewHelpers

Defined in:
lib/acts_as_railable/view_helpers.rb

Instance Method Summary collapse

Instance Method Details



7
8
9
# File 'lib/acts_as_railable/view_helpers.rb', line 7

def back_link_to name, html_options
  link_to name, "javascript:history.go(-1);", html_options
end

#bootstrap_devise_error_messages!(resource) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/acts_as_railable/view_helpers.rb', line 119

def bootstrap_devise_error_messages!(resource)
  return "" if resource.errors.empty?

  form_error_id = resource.try(:form_error_placeholder_id) || "error_explanation"

  messages = resource.errors.full_messages.map { |msg| (:li, msg) }.join
  sentence = I18n.t("errors.messages.not_saved",
                    count: resource.errors.count,
                    resource: resource.class.model_name.human.downcase)
  bodyhead = I18n.t("errors.template.body")

  html = <<-HTML
    <div id="#{form_error_id}">
      <div class="alert alert-danger" role="alert">
        <h6 class="alert-heading">#{sentence}</h6>
        <ul class="mb-0">#{messages}</ul>
      </div>
    </div>
  HTML

  html.html_safe
end

#bootstrap_flash_messages!Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/acts_as_railable/view_helpers.rb', line 27

def bootstrap_flash_messages!
  html = ""
  flash.each do |name, msg|
    if msg.is_a? String
      color_code = name == 'notice' ? 'success' : 'danger'
      flash_class = "alert alert-#{color_code} alert-dismissible fade show"
      html += <<-HTML
      <div class="#{flash_class}" role="alert">
        <div>#{msg}</div>
        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
      </div>
      HTML
    end
  end
  html.html_safe
end

#bootstrap_form_error_messages!(object) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/acts_as_railable/view_helpers.rb', line 70

def bootstrap_form_error_messages!(object)
  form_error_id = object.try(:form_error_placeholder_id) || "error_explanation"

  if object.errors.any?
    messages = object.errors.full_messages.map { |msg| (:li, msg) }.join
    sentence = I18n.t("errors.template.header",
                      count: object.errors.count,
                      model: object.class.model_name.human.downcase)
    bodyhead = I18n.t("errors.template.body")

    html = <<-HTML
      <div id="#{form_error_id}">
        <div class="alert alert-danger" role="alert">
          <h6 class="alert-heading">#{sentence}</h6>
          <ul class="mb-0">#{messages}</ul>
        </div>
      </div>
    HTML
  else
    html = <<-HTML
      <div id="#{form_error_id}">
      </div>
    HTML
  end

  html.html_safe
end

#native_devise_error_messages!(resource) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/acts_as_railable/view_helpers.rb', line 98

def native_devise_error_messages!(resource)
  return "" if resource.errors.empty?

  form_error_id = resource.try(:form_error_placeholder_id) || "error_explanation"

  messages = resource.errors.full_messages.map { |msg| (:li, msg) }.join
  sentence = I18n.t("errors.messages.not_saved",
                    count: resource.errors.count,
                    resource: resource.class.model_name.human.downcase)
  bodyhead = I18n.t("errors.template.body")

  html = <<-HTML
    <div id="#{form_error_id}">
      <h2>#{sentence}</h2>
      <ul>#{messages}</ul>
    </div>
  HTML

  html.html_safe
end

#native_flash_messages!Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/acts_as_railable/view_helpers.rb', line 11

def native_flash_messages!
  html = ""
  flash.each do |name, msg|
    if msg.is_a? String
      color_code = name == 'notice' ? 'green' : 'red'
      flash_style = "color: #{color_code}"
      html += <<-HTML
      <p style="#{flash_style}">
        #{msg}
      </p>
      HTML
    end
  end
  html.html_safe
end

#native_form_error_messages!(object) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/acts_as_railable/view_helpers.rb', line 44

def native_form_error_messages!(object)
  form_error_id = object.try(:form_error_placeholder_id) || "error_explanation"

  if object.errors.any?
    messages = object.errors.full_messages.map { |msg| (:li, msg) }.join
    sentence = I18n.t("errors.template.header",
                      count: object.errors.count,
                      model: object.class.model_name.human.downcase)
    bodyhead = I18n.t("errors.template.body")

    html = <<-HTML
      <div id="#{form_error_id}" style="color: red">
        <h2>#{sentence}</h2>
        <ul>#{messages}</ul>
      </div>
    HTML
  else
    html = <<-HTML
      <div id="#{form_error_id}">
      </div>
    HTML
  end

  html.html_safe
end


3
4
5
# File 'lib/acts_as_railable/view_helpers.rb', line 3

def void_link_to name, html_options=nil
  link_to name, "javascript:void(0);", html_options
end