Module: Ditty::Helpers::Pundit
- Includes:
- Pundit
- Defined in:
- lib/ditty/helpers/pundit.rb
Instance Method Summary collapse
- #authorize(record, query) ⇒ Object
- #permitted_attributes(record, action) ⇒ Object
- #pundit_user ⇒ Object
Instance Method Details
#authorize(record, query) ⇒ Object
10 11 12 13 |
# File 'lib/ditty/helpers/pundit.rb', line 10 def (record, query) query = :"#{query}?" unless query[-1] == '?' super end |
#permitted_attributes(record, action) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ditty/helpers/pundit.rb', line 15 def permitted_attributes(record, action) param_key = PolicyFinder.new(record).param_key policy = policy(record) method_name = if policy.respond_to?("permitted_attributes_for_#{action}") "permitted_attributes_for_#{action}" else 'permitted_attributes' end request.params.fetch(param_key, {}).select do |key, _value| policy.public_send(method_name).include? key.to_sym end end |
#pundit_user ⇒ Object
29 30 31 |
# File 'lib/ditty/helpers/pundit.rb', line 29 def pundit_user current_user end |