Module: ActiveEntry::ViewHelper
- Defined in:
- app/helpers/active_entry/view_helper.rb
Instance Method Summary collapse
- #authorized_for?(controller_name, action, **args) ⇒ Boolean
- #link_to_if_authorized(name = nil, options = nil, html_options = nil, **args, &block) ⇒ Object
Instance Method Details
#authorized_for?(controller_name, action, **args) ⇒ Boolean
3 4 5 6 7 |
# File 'app/helpers/active_entry/view_helper.rb', line 3 def controller_name, action, **args controller_name = controller_name.to_s.camelize.remove "Controller" policy = ActiveEntry::PolicyFinder.policy_for controller_name policy::Authorization.pass? action, **args end |
#link_to_if_authorized(name = nil, options = nil, html_options = nil, **args, &block) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'app/helpers/active_entry/view_helper.rb', line 9 def name = nil, = nil, = nil, **args, &block url = url_for method = &.is_a?(Hash) && [:method] ? [:method].to_s.upcase : "GET" recognized_path = Rails.application.routes.recognize_path(url, method: method) = recognized_path[:controller], recognized_path[:action], **args link_to name, , , &block if end |