realtime-validations 0.0.3 → 0.0.4
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/README.rdoc
CHANGED
@@ -1,3 +1,67 @@
|
|
1
|
-
=
|
1
|
+
= Realtime Validations for Rails
|
2
2
|
|
3
|
-
|
3
|
+
Gem that is able to run validations on models while the form is being filled by the user.
|
4
|
+
|
5
|
+
== Why
|
6
|
+
|
7
|
+
It is smart in the sense that is able to fulfill almost any kind of validation. For instance, if
|
8
|
+
configured properly, it can run even validations that are :scoped by some other model.
|
9
|
+
|
10
|
+
Also, it allows to add some information based on the current session, user, client... so the model
|
11
|
+
to be created or edited can be linked to that session, user or client.
|
12
|
+
|
13
|
+
It is very generic and is not tied to any specific case of use.
|
14
|
+
|
15
|
+
== How it works
|
16
|
+
|
17
|
+
It is installed a listener on every field of the form to be validated, so when the user leaves the
|
18
|
+
field, a petition is made to the server. The server (the ValidationsController class) will then create
|
19
|
+
a new model of that type, or will find the current one (if it is an edit/update operation). Then,
|
20
|
+
the property that was edited by the user is set to this recently created model instance. Right
|
21
|
+
afterwards, it is called a helper that will allow you (the developer) to set some special fields
|
22
|
+
that have importance to you, as the session, current client or current user, in order to be able to
|
23
|
+
correctly process all validations, even those that are scoped on the current user, for example. After
|
24
|
+
calling your helper, the valid? method is called on the model; the errors[:field_name] is retrieved
|
25
|
+
and returned to the client, for the JQuery code to process and modify the DOM.
|
26
|
+
|
27
|
+
== Setup
|
28
|
+
|
29
|
+
=== Gemfile
|
30
|
+
|
31
|
+
require 'realtime-validations'
|
32
|
+
|
33
|
+
=== Running generators
|
34
|
+
|
35
|
+
rails g realtime_validations realtime_validations
|
36
|
+
|
37
|
+
Read more about what the generators do on the Wiki pages.
|
38
|
+
|
39
|
+
=== Putting everything together
|
40
|
+
|
41
|
+
=== Application Layout
|
42
|
+
|
43
|
+
Include javascripts and stylesheets (optionally) from the engine in your layout file:
|
44
|
+
|
45
|
+
<%= stylesheet_link_tag 'application', 'realtime_validations/core' %>
|
46
|
+
<%= javascript_include_tag 'application', 'realtime_validations/core' %>
|
47
|
+
|
48
|
+
==== Views
|
49
|
+
|
50
|
+
You should use:
|
51
|
+
|
52
|
+
form_validated_for
|
53
|
+
|
54
|
+
=== Check if the engine is correctly imported
|
55
|
+
|
56
|
+
Run:
|
57
|
+
|
58
|
+
rake routes
|
59
|
+
|
60
|
+
and check if it contains a route for:
|
61
|
+
|
62
|
+
POST /validations/*args(.:format) realtime_validations/validations#validate
|
63
|
+
|
64
|
+
=== Examples
|
65
|
+
|
66
|
+
https://github.com/ereslibre/realtime-validations-examples contains some examples that can
|
67
|
+
be of use if you are starting to use this gem.
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module RealtimeValidations
|
4
|
+
|
5
|
+
module Generators
|
6
|
+
|
7
|
+
class InstallGenerator < Rails::Generators::Base
|
8
|
+
|
9
|
+
source_root File.join(File.dirname(__FILE__), 'templates')
|
10
|
+
|
11
|
+
def copy_initializer_file
|
12
|
+
copy_file 'initializer.rb', 'config/initializers/realtime_validations_initializer.rb'
|
13
|
+
copy_file 'realtime_validations.js', 'app/assets/javascripts/realtime_validations.js'
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: realtime-validations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-12-30 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &8517220 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.1.3
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *8517220
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: sqlite3
|
27
|
-
requirement: &
|
27
|
+
requirement: &8516800 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *8516800
|
36
36
|
description: Form real time validations for free on Rails applications
|
37
37
|
email:
|
38
38
|
- ereslibre@gmail.com
|
@@ -47,9 +47,9 @@ files:
|
|
47
47
|
- config/initializers/form_validated_for.rb
|
48
48
|
- lib/realtime-validations.rb
|
49
49
|
- lib/realtime-validations/version.rb
|
50
|
+
- lib/generators/realtime_validations/install_generator.rb
|
50
51
|
- lib/generators/realtime_validations/templates/initializer.rb
|
51
52
|
- lib/generators/realtime_validations/templates/realtime_validations.js
|
52
|
-
- lib/generators/realtime_validations/realtime_validations_generator.rb
|
53
53
|
- lib/tasks/realtime-validations_tasks.rake
|
54
54
|
- MIT-LICENSE
|
55
55
|
- Rakefile
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'rails/generators'
|
2
|
-
|
3
|
-
class RealtimeValidationsGenerator < Rails::Generators::NamedBase
|
4
|
-
|
5
|
-
source_root File.join(File.dirname(__FILE__), 'templates')
|
6
|
-
|
7
|
-
def copy_initializer_file
|
8
|
-
copy_file 'initializer.rb', 'config/initializers/realtime_validations_initializer.rb'
|
9
|
-
copy_file 'realtime_validations.js', 'app/assets/javascripts/realtime_validations.js'
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|