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.
@@ -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 +app.rb+ file:
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 +app/views/shared+ you'll two new partials should be present:
24
+ Now in <tt>app/views/shared</tt> you'll two new partials should be present:
25
25
 
26
- +_error_messages.html.*+ :: template for error_messages_for
27
- +_error_message.html.*+ :: template for error_message_on
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
- You can freely modify views listed above. In +_error_messages+ you can use
32
- following local variables:
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
- +object+ :: main object passed in arguments (or associated with form)
35
- +errors+ :: merged list with errors
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.5
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
- <%- object.errors.full_messages.each do |msg| %>
5
- <li><%= msg %></li>
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
+
@@ -1,5 +1,6 @@
1
1
  .errors-explanation
2
- %h3 #{object.class.human_name} couldn not be saved
2
+ %h3 #{object.class.human_name} could not be saved
3
3
  %ul
4
- - object.errors.full_messages.each do |msg|
5
- %li= msg
4
+ - objects.each do |o|
5
+ - o.errors.full_messages.each do |msg|
6
+ %li= msg
@@ -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 = objects.map {|object| object.errors }.flatten
25
- if errors.size > 0
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
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{padrino-form-errors}
8
- s.version = "0.0.5"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kriss 'nu7hatch' Kowalik"]
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: 21
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 5
10
- version: 0.0.5
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kriss 'nu7hatch' Kowalik