safai 0.0.14 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/safai.rb +30 -29
- metadata +1 -1
data/lib/safai.rb
CHANGED
@@ -114,49 +114,50 @@ class Safai
|
|
114
114
|
|
115
115
|
module DeviseHelpers
|
116
116
|
|
117
|
-
|
118
|
-
|
119
|
-
|
117
|
+
def resource_name
|
118
|
+
:user
|
119
|
+
end
|
120
120
|
|
121
|
-
|
122
|
-
|
123
|
-
|
121
|
+
def resource
|
122
|
+
@resource ||= User.new
|
123
|
+
end
|
124
124
|
|
125
|
-
|
126
|
-
|
127
|
-
|
125
|
+
def devise_mapping
|
126
|
+
@devise_mapping ||= Devise.mappings[:user]
|
127
|
+
end
|
128
128
|
|
129
|
-
|
129
|
+
#DEVISE end
|
130
130
|
|
131
|
-
|
132
|
-
|
133
|
-
|
131
|
+
def devise_error_messages!
|
132
|
+
flash_alerts = []
|
133
|
+
error_key = 'errors.messages.not_saved'
|
134
134
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
135
|
+
if !flash.empty?
|
136
|
+
flash_alerts.push(flash[:error]) if flash[:error]
|
137
|
+
flash_alerts.push(flash[:alert]) if flash[:alert]
|
138
|
+
flash_alerts.push(flash[:notice]) if flash[:notice]
|
139
|
+
error_key = 'devise.failure.invalid'
|
140
|
+
end
|
141
141
|
|
142
|
-
|
143
|
-
|
142
|
+
return "" if resource.errors.empty? && flash_alerts.empty?
|
143
|
+
errors = resource.errors.empty? ? flash_alerts : resource.errors.full_messages
|
144
144
|
|
145
|
-
|
146
|
-
|
145
|
+
messages = errors.map { |msg| content_tag(:li, msg) }.join
|
146
|
+
sentence = I18n.t(error_key, :count => errors.count,
|
147
147
|
:resource => resource.class.model_name.human.downcase)
|
148
148
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
149
|
+
html = <<-HTML
|
150
|
+
<div id="error_explanation">
|
151
|
+
<h2>#{sentence}</h2>
|
152
|
+
<ul>#{messages}</ul>
|
153
|
+
</div>
|
154
|
+
HTML
|
155
155
|
|
156
156
|
html.html_safe
|
157
157
|
end
|
158
158
|
|
159
159
|
end
|
160
|
+
end
|
160
161
|
|
161
162
|
#======================================
|
162
163
|
|