comply 1.7.0 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6baf5ccbed26227f68924f4fd6e771212d5453f8
|
4
|
+
data.tar.gz: a9f6ad3d2403b258a0b6474c84ff106730424143
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2d121eafee9f87871559812c2d5b77fba805a91adcbd2fbb8271799a1612afac796823ac4b67cf9ff2dee6e6627fb745f7ea846457e43930aa452eb24b72bcd
|
7
|
+
data.tar.gz: f2fc14f21bf83e8fb8dbd94dce17e8ec3ac6a92eb7db0df0fc1e7e18b6d1173e9f5b5e6f2649e9346b391b93a83b2659f81ee0a945a342e46e5e38266bb2dbc4
|
data/README.md
CHANGED
@@ -68,6 +68,45 @@ Want success messages to add some personality to your forms? Add the message as
|
|
68
68
|
<%= f.text_field :title, data: { validate: true, validate_success: "Sweet title yo!" } %>
|
69
69
|
```
|
70
70
|
|
71
|
+
### Validation contexts
|
72
|
+
Supplementary reading on validation contexts:
|
73
|
+
- [ActiveRecord Validations :on](http://guides.rubyonrails.org/active_record_validations.html#on)
|
74
|
+
- [Also see api.rubyonrails.org](http://api.rubyonrails.org/classes/ActiveRecord/Validations.html#method-i-valid-3F)
|
75
|
+
- [Mastering Rails Validations: Contexts](http://blog.arkency.com/2014/04/mastering-rails-validations-contexts/)
|
76
|
+
|
77
|
+
By default, all validations run through Comply's `Comply::ValidationsController` will be in the `:comply` validation
|
78
|
+
context. This gives you the option to modify how your application runs its validations. The most common way to use
|
79
|
+
validation contexts, is when you want to skip a certain validation. Let's say we didn't want to check the uniqueness
|
80
|
+
of a particular attribute when asking Comply to validate a model. You would do this:
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
class SomeModel < ActiveRecord::Base
|
84
|
+
validates :my_attribute, uniqueness: true, unless: -> { validation_context == :comply }
|
85
|
+
# or perhaps you *ONLY* want to run the validation when in the :comply context
|
86
|
+
validates :other_attribute, numericality: true, on: :comply
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
90
|
+
You now have the option to specify your own context if you inherit from `Comply::ValidationsController` if your
|
91
|
+
model has a specific business case for needing to run/not-run a set of validations for a given context.
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
class SomeController < Comply::ValidationsController
|
95
|
+
# ... snip
|
96
|
+
protected
|
97
|
+
|
98
|
+
def validation_context
|
99
|
+
:my_new_context
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
class SomeModel
|
104
|
+
validates :my_attribute, uniqueness: true, unless: -> { validation_context == :my_new_context }
|
105
|
+
end
|
106
|
+
```
|
107
|
+
|
108
|
+
That's it!
|
109
|
+
|
71
110
|
### Event triggers
|
72
111
|
You can change the jQuery event which triggers the input validation with the `data-validate-event` attribute.
|
73
112
|
```erb
|
@@ -14,7 +14,7 @@ class Comply.BaseValidatableForm
|
|
14
14
|
@validate inputs: @inputs, submit: true
|
15
15
|
|
16
16
|
validate: (options) ->
|
17
|
-
$.
|
17
|
+
$.post @validationRoute, @_params(), (response) =>
|
18
18
|
@_onValidate(response, options)
|
19
19
|
|
20
20
|
if @_allSuccess(response)
|
@@ -12,11 +12,18 @@ module Comply
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def show
|
15
|
+
ActiveSupport::Deprecation.warn('GET support going away: use POST to access this endpoint') if request.request_method == 'GET'
|
15
16
|
@instance = validation_instance
|
16
|
-
@instance.valid?(
|
17
|
+
@instance.valid?(validation_context)
|
17
18
|
render json: { error: @instance.errors }
|
18
19
|
end
|
19
20
|
|
21
|
+
protected
|
22
|
+
|
23
|
+
def validation_context
|
24
|
+
:comply
|
25
|
+
end
|
26
|
+
|
20
27
|
private
|
21
28
|
|
22
29
|
def validation_instance
|
data/config/routes.rb
CHANGED
data/lib/comply/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: comply
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "@jacobaweiss"
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2016-
|
15
|
+
date: 2016-10-10 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: coffee-rails
|
@@ -128,8 +128,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
128
|
version: '0'
|
129
129
|
requirements: []
|
130
130
|
rubyforge_project:
|
131
|
-
rubygems_version: 2.2.
|
131
|
+
rubygems_version: 2.2.5
|
132
132
|
signing_key:
|
133
133
|
specification_version: 4
|
134
134
|
summary: Inline validation of your ActiveRecord models via the AJAX internets
|
135
135
|
test_files: []
|
136
|
+
has_rdoc:
|