error_messages_for_helper 1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,33 @@
1
+ ErrorMessagesForHelper
2
+ ================
3
+
4
+ Rails 3.0.x error_messages_for_helper plugin.
5
+
6
+
7
+ Example
8
+ =======
9
+
10
+ <%= form_for :test, :url => {:action => 'create'}, :html => {:method => :post} do |f| %>
11
+ <%= error_messages_for :test %>
12
+ <%= f.text_field :name %>
13
+ <%= f.text_field :age %>
14
+ <% end %>
15
+
16
+ When @test.errors is not empty then output for error_messages_for will be:
17
+
18
+ <div class="errorExplanation" id="errorExplanation">
19
+ <h2>Unable to save data.</h2>
20
+ <p>Errors list:</p>
21
+ <ul>
22
+ <li>Can't be empty</li>
23
+ <li>Must be integer</li>
24
+ <li>
25
+ </div>
26
+
27
+ For custom messages in your locale put this section:
28
+
29
+ error_messages_for:
30
+ header_message: 'Unable to save data.'
31
+ error_list: 'Errors list:'
32
+
33
+ Copyright (c) 2011 [Damian Baćkowski], released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rdoc/task'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the error_messages_for plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ end
15
+
16
+ desc 'Generate documentation for the error_messages_for plugin.'
17
+ RDoc::Task.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'ErrorMessagesFor'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
@@ -0,0 +1,22 @@
1
+ module ErrorMessagesForHelper
2
+ def error_messages_for(object_name)
3
+ model = instance_variable_get("@#{object_name}")
4
+
5
+ unless model.nil? || model.errors.empty?
6
+ errors_list = capture do
7
+ content_tag :ul do
8
+ model.errors.each do |attr,message|
9
+ concat(content_tag :li, message)
10
+ end
11
+ end
12
+ end
13
+
14
+ result = content_tag :h2, t(:header_message, :scope => 'error_messages_for', :default => 'Unable to save data.').html_safe
15
+ result << content_tag(:p, t(:error_list, :scope => 'error_messages_for', :default => 'Errors list:').html_safe)
16
+ result << errors_list
17
+ result = content_tag :div, result, :id => 'errorExplanation', :class => 'errorExplanation'
18
+ end
19
+ end
20
+ end
21
+
22
+ ActionView::Base.send :include, ErrorMessagesForHelper
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class ErrorMessagesForHelperTest < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'active_support'
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: error_messages_for_helper
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ version: "1.0"
10
+ platform: ruby
11
+ authors:
12
+ - "Damian Ba\xC4\x87kowski"
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-08-29 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies: []
20
+
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).
22
+ email: damianbackowski@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - Rakefile
31
+ - lib/error_messages_for_helper.rb
32
+ - test/error_messages_for_helper_test.rb
33
+ - test/test_helper.rb
34
+ - README
35
+ has_rdoc: false
36
+ homepage: https://github.com/paki-paki/error_messages_for_helper
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ hash: 3
50
+ segments:
51
+ - 0
52
+ version: "0"
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.6.2
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Active Record error messages helper for Rails 3.0.x
69
+ test_files: []
70
+