mirror of
https://github.com/varvet/pundit.git
synced 2022-11-09 12:30:11 -05:00
Fixes and simplifications for previous commit (to be squashed)
This commit is contained in:
parent
12602720a5
commit
db74632a90
3 changed files with 7 additions and 4 deletions
|
@ -1,5 +1,7 @@
|
|||
# Pundit
|
||||
|
||||
- Add autodetection of param key to `permitted_attributes` helper with ability to override it with `param_key` option.
|
||||
|
||||
## 1.0.1 (2015-05-27)
|
||||
|
||||
- Fixed a regression where NotAuthorizedError could not be ininitialized with a string.
|
||||
|
|
|
@ -141,10 +141,10 @@ module Pundit
|
|||
|
||||
def permitted_attributes(record, options={})
|
||||
name = options.delete(:param_key)
|
||||
name ||= if record.class.respond_to?(:model_name) # ActiveModel and ActiveRecord
|
||||
record.class.model_name.param_key
|
||||
elsif record.respond_to?(:model_name)
|
||||
name ||= if record.respond_to?(:model_name) # ActiveModel and ActiveRecord
|
||||
record.model_name.param_key
|
||||
elsif record.is_a?(Class)
|
||||
record.to_s.demodulize.underscore
|
||||
else
|
||||
record.class.to_s.demodulize.underscore
|
||||
end
|
||||
|
|
|
@ -58,7 +58,8 @@ end
|
|||
|
||||
module Customer
|
||||
class Post < Post
|
||||
def self.model_name
|
||||
# In ActiveRecord this method is accessible at both object and class level
|
||||
def model_name
|
||||
OpenStruct.new(param_key: 'customer_post')
|
||||
end
|
||||
def policy_class
|
||||
|
|
Loading…
Reference in a new issue