error_messages_for_helper 1.0.1 → 1.1.0

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.
Files changed (3) hide show
  1. data/README +30 -7
  2. data/lib/error_messages_for_helper.rb +13 -7
  3. metadata +6 -6
data/README CHANGED
@@ -1,20 +1,21 @@
1
- ErrorMessagesForHelper
2
- ================
1
+ # ErrorMessagesForHelper #
3
2
 
4
- Rails 3.0.x error_messages_for_helper plugin.
3
+ Rails 3.2.x error_messages_for_helper plugin.
5
4
 
6
5
 
7
- Example
8
- =======
6
+ ### Example ###
9
7
 
8
+ ```ruby
10
9
  <%= form_for :test, :url => {:action => 'create'}, :html => {:method => :post} do |f| %>
11
10
  <%= error_messages_for :test %>
12
11
  <%= f.text_field :name %>
13
12
  <%= f.text_field :age %>
14
13
  <% end %>
14
+ ```
15
15
 
16
- When @test.errors is not empty then output for error_messages_for will be:
16
+ When @test.errors is not empty error_messages_for will output:
17
17
 
18
+ ```html
18
19
  <div class="error_explanation">
19
20
  <h2>Unable to save data.</h2>
20
21
  <p>Errors list:</p>
@@ -23,6 +24,9 @@ When @test.errors is not empty then output for error_messages_for will be:
23
24
  <li>Must be integer</li>
24
25
  <li>
25
26
  </div>
27
+ ```
28
+
29
+ ### Customize ###
26
30
 
27
31
  For custom messages in your locale put this section:
28
32
 
@@ -30,4 +34,23 @@ error_messages_for:
30
34
  header_message: 'Unable to save data.'
31
35
  error_list: 'Errors list:'
32
36
 
33
- Copyright (c) 2011 [Damian Baćkowski], released under the MIT license
37
+ You can set global CSS class by html_options:
38
+
39
+ ```ruby
40
+ ErrorMessagesForHelper.html_options(:class => 'alert alert-error')
41
+ ```
42
+
43
+ output:
44
+
45
+ ```html
46
+ <div class="alert alert-error">
47
+ <h2>Unable to save data.</h2>
48
+ <p>Errors list:</p>
49
+ <ul>
50
+ <li>Can't be empty</li>
51
+ <li>Must be integer</li>
52
+ <li>
53
+ </div>
54
+ ```
55
+
56
+ Copyright (c) 2012 [Damian Baćkowski], released under the MIT license
@@ -1,20 +1,26 @@
1
1
  module ErrorMessagesForHelper
2
+ @@html_options = { :id => 'error_explanation' }
3
+
4
+ def self.html_options(options)
5
+ @@html_options = options
6
+ end
7
+
2
8
  def error_messages_for(object_name)
3
9
  model = instance_variable_get("@#{object_name}")
4
-
5
- unless model.nil? || model.errors.empty?
10
+
11
+ if model.present? && model.errors.present?
6
12
  errors_list = capture do
7
- content_tag :ul do
8
- model.errors.each do |attr,message|
13
+ content_tag :ul do
14
+ model.errors.each do |attr, message|
9
15
  concat(content_tag :li, message)
10
16
  end
11
17
  end
12
18
  end
13
-
14
- result = content_tag :h2, t(:header_message, :scope => 'error_messages_for', :default => 'Unable to save data.').html_safe
19
+
20
+ result = content_tag :h2, t(:header_message, :scope => 'error_messages_for', :default => 'Unable to save data.').html_safe
15
21
  result << content_tag(:p, t(:error_list, :scope => 'error_messages_for', :default => 'Errors list:').html_safe)
16
22
  result << errors_list
17
- result = content_tag :div, result, :id => 'error_explanation'
23
+ result = content_tag :div, result, @@html_options
18
24
  end
19
25
  end
20
26
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: error_messages_for_helper
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 0
9
8
  - 1
10
- version: 1.0.1
9
+ - 0
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Damian Ba\xC4\x87kowski"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-21 00:00:00 Z
18
+ date: 2012-09-21 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: error_messages_for_helper provides a simple helper to show ActiveRecord validation errors (just like old helper error_messages_for for Rails-2.3.x).
@@ -29,8 +29,8 @@ extra_rdoc_files: []
29
29
  files:
30
30
  - Rakefile
31
31
  - lib/error_messages_for_helper.rb
32
- - test/test_helper.rb
33
32
  - test/error_messages_for_helper_test.rb
33
+ - test/test_helper.rb
34
34
  - README
35
35
  homepage: https://github.com/paki-paki/error_messages_for_helper
36
36
  licenses: []
@@ -64,6 +64,6 @@ rubyforge_project:
64
64
  rubygems_version: 1.8.10
65
65
  signing_key:
66
66
  specification_version: 3
67
- summary: Active Record error messages helper for Rails 3.0.x
67
+ summary: Active Record error messages helper for Rails 3.2.x
68
68
  test_files: []
69
69