diff --git a/README.md b/README.md index bef32c0..5ca1f19 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/app/models/policy_manager/concerns/user_behavior.rb b/app/models/policy_manager/concerns/user_behavior.rb index c4c4bb8..e6b8ea9 100644 --- a/app/models/policy_manager/concerns/user_behavior.rb +++ b/app/models/policy_manager/concerns/user_behavior.rb @@ -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 \ No newline at end of file diff --git a/lib/policy_manager/version.rb b/lib/policy_manager/version.rb index 6c9b96e..67c7aea 100644 --- a/lib/policy_manager/version.rb +++ b/lib/policy_manager/version.rb @@ -1,3 +1,3 @@ module PolicyManager - VERSION = '0.2.2' + VERSION = '0.2.3' end