padrino-form-errors 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +17 -8
- data/VERSION +1 -1
- data/lib/padrino-form-errors/generators/templates/erb/_error_messages.erb.tt +5 -2
- data/lib/padrino-form-errors/generators/templates/haml/_error_messages.haml.tt +4 -3
- data/lib/padrino-form-errors/helpers/form_helpers.rb +4 -3
- data/padrino-form-errors.gemspec +1 -1
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -9,7 +9,7 @@ Install plugin via rubygems:
|
|
9
9
|
|
10
10
|
gem install padrino-form-errors
|
11
11
|
|
12
|
-
And register plugin in your
|
12
|
+
And register plugin in your <tt>app.rb</tt> file:
|
13
13
|
|
14
14
|
class MyApp < Padrino::Application
|
15
15
|
register Padrino::Helpers
|
@@ -21,18 +21,27 @@ Now you can run generator:
|
|
21
21
|
|
22
22
|
padrino-gen form_errors
|
23
23
|
|
24
|
-
Now in
|
24
|
+
Now in <tt>app/views/shared</tt> you'll two new partials should be present:
|
25
25
|
|
26
|
-
|
27
|
-
|
26
|
+
<tt>_error_messages.html.*</tt> :: template for error_messages_for
|
27
|
+
<tt>_error_message.html.*</tt> :: template for error_message_on
|
28
|
+
|
29
|
+
You can freely modify views listed above.
|
28
30
|
|
29
31
|
== Overriding templates
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
+
In +_error_messages+ you can use following local variables:
|
34
|
+
|
35
|
+
+object+ :: main object passed in arguments (or associated with form)
|
36
|
+
+objects+ :: list of all objects passed in arguments
|
37
|
+
|
38
|
+
You can display all errors using <tt>#errors</tt> method from specified object, eg:
|
33
39
|
|
34
|
-
|
35
|
-
|
40
|
+
%h3= #{object.class.human_name} couldn't be saved
|
41
|
+
%ul
|
42
|
+
- objects.each do |o|
|
43
|
+
- o.errors.full_messages.each do |msg|
|
44
|
+
%li= msg
|
36
45
|
|
37
46
|
In +_error_message+ there are following local variables:
|
38
47
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
@@ -1,8 +1,11 @@
|
|
1
1
|
<div class="errors-explanation">
|
2
2
|
<h3><%= object.class.human_name %> couldn not be saved</h3>
|
3
3
|
<ul>
|
4
|
-
<%-
|
5
|
-
|
4
|
+
<%- objects.each do |o| %>
|
5
|
+
<%- o.errors.full_messages.each do |msg| %>
|
6
|
+
<li><%= msg %></li>
|
7
|
+
<%- end -%>
|
6
8
|
<%- end %>
|
7
9
|
</ul>
|
8
10
|
</div>
|
11
|
+
|
@@ -12,6 +12,7 @@ module Padrino
|
|
12
12
|
# -# ...
|
13
13
|
#
|
14
14
|
def error_messages_for(*objects)
|
15
|
+
errors = 0
|
15
16
|
objects.map! do |object|
|
16
17
|
if object.is_a? Symbol
|
17
18
|
instance_variable_get("@#{object}")
|
@@ -20,10 +21,10 @@ module Padrino
|
|
20
21
|
else
|
21
22
|
object
|
22
23
|
end
|
24
|
+
errors += object.errors.size and object
|
23
25
|
end
|
24
|
-
errors
|
25
|
-
|
26
|
-
partial "shared/error_messages", :locals => { :object => objects.first, :errors => errors }
|
26
|
+
if errors > 0
|
27
|
+
partial "shared/error_messages", :locals => { :object => objects.first, :objects => objects }
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
data/padrino-form-errors.gemspec
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: padrino-form-errors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.5
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kriss 'nu7hatch' Kowalik
|