realtime-validations 0.0.4 → 0.0.6
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
@@ -4,7 +4,7 @@ Gem that is able to run validations on models while the form is being filled by
|
|
4
4
|
|
5
5
|
== Why
|
6
6
|
|
7
|
-
It is smart in the sense that is able to fulfill
|
7
|
+
It is smart in the sense that is able to fulfill any kind of validation. For instance, if
|
8
8
|
configured properly, it can run even validations that are :scoped by some other model.
|
9
9
|
|
10
10
|
Also, it allows to add some information based on the current session, user, client... so the model
|
@@ -12,27 +12,15 @@ to be created or edited can be linked to that session, user or client.
|
|
12
12
|
|
13
13
|
It is very generic and is not tied to any specific case of use.
|
14
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
15
|
== Setup
|
28
16
|
|
29
17
|
=== Gemfile
|
30
18
|
|
31
|
-
|
19
|
+
gem 'realtime-validations'
|
32
20
|
|
33
21
|
=== Running generators
|
34
22
|
|
35
|
-
rails g realtime_validations
|
23
|
+
rails g realtime_validations:install
|
36
24
|
|
37
25
|
Read more about what the generators do on the Wiki pages.
|
38
26
|
|
@@ -40,7 +28,7 @@ Read more about what the generators do on the Wiki pages.
|
|
40
28
|
|
41
29
|
=== Application Layout
|
42
30
|
|
43
|
-
Include javascripts and stylesheets (optionally) from the engine in your layout file:
|
31
|
+
Include javascripts and stylesheets (optionally) from the engine in your application layout file:
|
44
32
|
|
45
33
|
<%= stylesheet_link_tag 'application', 'realtime_validations/core' %>
|
46
34
|
<%= javascript_include_tag 'application', 'realtime_validations/core' %>
|
@@ -51,6 +39,12 @@ You should use:
|
|
51
39
|
|
52
40
|
form_validated_for
|
53
41
|
|
42
|
+
instead of:
|
43
|
+
|
44
|
+
form_for
|
45
|
+
|
46
|
+
where you want the engine to validate your fields automatically.
|
47
|
+
|
54
48
|
=== Check if the engine is correctly imported
|
55
49
|
|
56
50
|
Run:
|
@@ -63,5 +57,4 @@ and check if it contains a route for:
|
|
63
57
|
|
64
58
|
=== Examples
|
65
59
|
|
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.
|
60
|
+
realtime-validations-examples[https://github.com/ereslibre/realtime-validations-examples] contains some examples that can be of use if you are starting to use this gem.
|
@@ -2,9 +2,34 @@ module RealtimeValidations
|
|
2
2
|
|
3
3
|
module Controller
|
4
4
|
|
5
|
+
#
|
6
|
+
# Called when this module is included in the ValidationsController.
|
7
|
+
#
|
8
|
+
# Here, you could add or remove new before and after filters, for instance.
|
9
|
+
#
|
10
|
+
# Example:
|
11
|
+
#
|
12
|
+
# base.skip_before_filter :some_applicationcontroller_filter
|
13
|
+
# base.before_filter :some_helper_method
|
14
|
+
#
|
5
15
|
def self.included(base)
|
6
16
|
end
|
7
17
|
|
18
|
+
#
|
19
|
+
# Called before model is validated. The model has already been filled with all the needed
|
20
|
+
# information in order to check whether is valid or not. Here, you could also add some
|
21
|
+
# extra information that has meaning for your system, as a client_id, a session_id, a
|
22
|
+
# user_id or something similar.
|
23
|
+
#
|
24
|
+
# Example:
|
25
|
+
#
|
26
|
+
# model.client_id = @client.id if @client and model.respond_to? :client_id=
|
27
|
+
# model.user_id = @user.id if @user and model.respond_to? :user_id=
|
28
|
+
#
|
29
|
+
# This is very important for validations on your model of the type:
|
30
|
+
#
|
31
|
+
# validates :name, :presence => true, :uniqueness => { :scope => :client_id }
|
32
|
+
#
|
8
33
|
def before_model_validation(model)
|
9
34
|
end
|
10
35
|
|
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.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-12-
|
12
|
+
date: 2011-12-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &19648320 !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: *19648320
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: sqlite3
|
27
|
-
requirement: &
|
27
|
+
requirement: &19647640 !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: *19647640
|
36
36
|
description: Form real time validations for free on Rails applications
|
37
37
|
email:
|
38
38
|
- ereslibre@gmail.com
|