rails_ember_validations 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/README.md +116 -2
- data/lib/generators/rails_ember_validations/install_generator.rb +1 -1
- data/lib/rails_ember_validations/version.rb +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29208c4de693622df2dbae560c321d4fc3b2a4bb
|
4
|
+
data.tar.gz: fe3646a91ffeb0007a71482f0c3eaf81c91ef08a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 637886743a63fa3984de0bd92a794bba11b3b4c63c102dc510a51948b1e22435409df2c990bd6a1183dd7b4bce3b331befe44fc7d6928ee366d48981ba076ce1
|
7
|
+
data.tar.gz: dc5f355f8c8a1a6c42968a3ee2d6ebcae78f5a00da650008670f68d053ac8b975b1531d4c637e827f69b8c0d44791527ee6e800d6e76a2acb1d68a5fefc134bc
|
data/README.md
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
# RailsEmberValidations
|
2
2
|
|
3
|
-
|
3
|
+
Rails_ember_validations is a gem for server-side validations in your forms.
|
4
|
+
Its use is for validations only, it will not process any actions, its up to you to handle the responce.
|
5
|
+
|
6
|
+
This gem was created for json responces with validation and authorization errors.
|
7
|
+
|
8
|
+
Although it is designed for functionality with ember.js , you can still use it with
|
9
|
+
anything you want.
|
10
|
+
|
11
|
+
|
12
|
+
Rails_ember_validations for ember use, works only with ember-data and it will fail if you use anything else for client persistence.
|
4
13
|
|
5
14
|
## Installation
|
6
15
|
|
@@ -16,9 +25,114 @@ Or install it yourself as:
|
|
16
25
|
|
17
26
|
$ gem install rails_ember_validations
|
18
27
|
|
28
|
+
For ember use , add
|
29
|
+
|
30
|
+
//= require validation-view
|
31
|
+
|
32
|
+
in your application.js file, after the rest of ember files.
|
33
|
+
|
19
34
|
## Usage
|
35
|
+
GENERAL
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
Just make a post request at /validate.json , passing your params as {"object_to_validate"=>{"attr1"=>"something", "attr2"=>"something",... }}
|
40
|
+
|
41
|
+
Example:
|
42
|
+
|
43
|
+
{"user"=>{"role"=>"administrator", "name"=>"User1", "id"=>"1"}}
|
44
|
+
|
45
|
+
If you sent an id in object's attributes ,server will validate it as new, else as update.
|
46
|
+
|
47
|
+
Server will validate ANY attribute , based on validations defined in the appropriate model.
|
48
|
+
Server will also authorize your object (using CanCan's authorize! method), if you use CanCan, else it will just proceed
|
49
|
+
in validation check.
|
50
|
+
|
51
|
+
Responce for validation errors will be : {"attr1"=> [array_of_errors_for_attr1], "attr2"=> [array_of_errors_for_attr2],... }}
|
52
|
+
|
53
|
+
Example:
|
54
|
+
|
55
|
+
{"password":["can't be blank","Weak Password"],"name":["can't be blank"]}
|
56
|
+
|
57
|
+
EMBER.JS
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
Simply include App.ValidationView at the top of your form.
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
Include any input you may have in a div with id {attribute}Validation
|
66
|
+
To see the error , call view.{attribute}Validation in an if view.{attribute}Validation block
|
67
|
+
|
68
|
+
Authorization errors are displayed by calling view.authorizationValidation in an if view.authorizationValidation block.
|
69
|
+
|
70
|
+
For example in the following form we get authorization errors at the top of our form and validation errors for name attribute spanned to our input element .
|
71
|
+
|
72
|
+
{{#view App.ValidationView }}
|
73
|
+
{{#if view.authorizationValidation}}
|
74
|
+
|
75
|
+
<div class="alert alert-error">
|
76
|
+
|
77
|
+
{{view.authorizationValidation}}
|
78
|
+
|
79
|
+
</div>
|
80
|
+
|
81
|
+
{{/if}}
|
82
|
+
|
83
|
+
<div id="nameInput" class="form-group">
|
84
|
+
|
85
|
+
<span>First Name </span>
|
86
|
+
|
87
|
+
{{input value=email type="text"}}
|
88
|
+
|
89
|
+
{{#if view.nameValidation}}
|
90
|
+
<div class="alert alert-error">
|
91
|
+
{{view.nameValidation}}
|
92
|
+
</div>
|
93
|
+
|
94
|
+
{{/if}}
|
95
|
+
</div>
|
96
|
+
|
97
|
+
{{/view}}
|
98
|
+
|
99
|
+
|
100
|
+
When server returns errors (if any) , validationView will try to find divs with id named after the error attributes.
|
101
|
+
It will add 'has-error' class at them, so if you'd like you can overide this class' styling .
|
102
|
+
|
103
|
+
If server returns no errors, view will trigger the save action of current controller, so place any logic following a valid request there.
|
104
|
+
ValidationView also comes with a cancel action embedded that rollsback any changes to record you were editing or deletes it if it was new.
|
105
|
+
|
106
|
+
|
107
|
+
Excluding model properties
|
108
|
+
|
109
|
+
When you have extra properties in your model that you don't want to be sent for validation, you can add inside your model a property array named excludedProperties and add any property that wont be sent for validation.
|
110
|
+
|
111
|
+
Example:
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
App.User = DS.Model.extend({
|
116
|
+
|
117
|
+
email: DS.attr('string'),
|
118
|
+
name: DS.attr('string'),
|
119
|
+
surname: DS.attr('string'),
|
120
|
+
|
121
|
+
can_edit: DS.attr('boolean'),
|
122
|
+
can_delete: DS.attr('boolean'),
|
123
|
+
can_read: DS.attr('boolean'),
|
124
|
+
can_manage: DS.attr('boolean'),
|
125
|
+
can_create: DS.attr('boolean'),
|
126
|
+
|
127
|
+
excludedProperties: ['can_edit', 'can_delete', 'can_read', 'can_manage', 'can_create'],
|
128
|
+
|
129
|
+
});
|
130
|
+
|
131
|
+
In the above when a user record is sent for validation , only name, surname and email are sent. Everything in excludedProperties is not.
|
132
|
+
|
133
|
+
|
134
|
+
|
20
135
|
|
21
|
-
TODO: Write usage instructions here
|
22
136
|
|
23
137
|
## Contributing
|
24
138
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_ember_validations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandros M
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -50,15 +50,16 @@ files:
|
|
50
50
|
- LICENSE.txt
|
51
51
|
- README.md
|
52
52
|
- Rakefile
|
53
|
-
- lib/rails_ember_validations.rb
|
54
|
-
- lib/rails_ember_validations/version.rb
|
55
|
-
- rails_ember_validations.gemspec
|
56
|
-
- app/controllers/rails_ember_validations/validations_controller.rb
|
57
53
|
- app/assets/javascripts/validation-view.js
|
54
|
+
- app/controllers/rails_ember_validations/validations_controller.rb
|
58
55
|
- config/routes.rb
|
59
|
-
- lib/rails_ember_validations/engine.rb
|
60
56
|
- lib/generators/rails_ember_validations/USAGE
|
61
57
|
- lib/generators/rails_ember_validations/install_generator.rb
|
58
|
+
- lib/rails_ember_validations.rb
|
59
|
+
- lib/rails_ember_validations/engine.rb
|
60
|
+
- lib/rails_ember_validations/version.rb
|
61
|
+
- rails_ember_validations-0.0.1.gem
|
62
|
+
- rails_ember_validations.gemspec
|
62
63
|
homepage: ''
|
63
64
|
licenses:
|
64
65
|
- MIT
|
@@ -84,4 +85,3 @@ signing_key:
|
|
84
85
|
specification_version: 4
|
85
86
|
summary: Server side validations
|
86
87
|
test_files: []
|
87
|
-
has_rdoc:
|