Sha256: 3f6a8ba0c612c31739cd29029e03f6ca59eb80d76c6343b26b87ef7f0db6cfc8

Contents?: true

Size: 757 Bytes

Versions: 3

Compression:

Stored size: 757 Bytes

Contents

module Curupira::AuthorizeHelper
  def link_to_authorize(name = nil, options = nil, html_options = nil, &block)
    html_options, options, name = options, name, block if block_given?
    options ||= {}

    html_options = convert_options_to_data_attributes(options, html_options)

    url = url_for(options)
    method = html_options["data-method"].to_s.upcase if html_options["data-method"]

    request_data = Rails.application.routes.recognize_path(url, method: method)

    if has_authorization_for(request_data)
      html_options['href'] ||= url
    else
      html_options['style'] = "cursor: not-allowed;"
      html_options['class'] = "#{html_options['class']} not-allowed";
    end

    content_tag(:a, name || url, html_options, &block)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
curupira-0.1.7 app/helpers/curupira/authorize_helper.rb
curupira-0.1.6 app/helpers/curupira/authorize_helper.rb
curupira-0.1.4 app/helpers/curupira/authorize_helper.rb