Skip to content

Commit

Permalink
Merge pull request #13 from prey/store_cookie-method
Browse files Browse the repository at this point in the history
store cookie method
  • Loading branch information
patriciojofre authored May 10, 2018
2 parents d6e5d1a + fb9bc1c commit 32ffc94
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ When the policies are configured will generate some helper methods on User model

**Use this in your controller:**
```ruby
@user.store_policy_cookie if cookies["policy_rule_cookie"] == "accepted"
@user.accept_policy_from("your_cookie") if cookies["policy_rule_your_cookie"] == "accepted"
```
+ **validates_on:** will require users validation, will automagically create virtual attributes for the policy you set, so, if you set `age` in your config you must supply in your forms a `policy_rule_age` checkbox in your form, if you don't supply those then the user validation will return errors on `policy_rule_age` . Don't forget to add the fields in your strong params in the controller which handles the request.
+ **if:** you can add conditions as a Proc in order skip validations:
Expand Down
8 changes: 8 additions & 0 deletions app/models/policy_manager/concerns/user_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,12 @@ def can_request_portability?
self.portability_requests.select{|p| p.pending? || p.progress?}.blank?
end

def accept_policy_from(name)
term = PolicyManager::Config.rules.find{|o| o.name == name}.terms.published.last
if term.present?
user_term = self.handle_policy_for(term)
user_term.accept! unless user_term.accepted?
end
end

end
2 changes: 1 addition & 1 deletion lib/policy_manager/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module PolicyManager
VERSION = '0.2.2'
VERSION = '0.2.3'
end

0 comments on commit 32ffc94

Please sign in to comment.