Sha256: 3717397ff83b75b5e389e411bca67c0bd1b308f67a567980abc257c50f6d9abf

Contents?: true

Size: 814 Bytes

Versions: 1

Compression:

Stored size: 814 Bytes

Contents

module Trestle
  module UrlHelper
    def admin_link_to(content, instance=nil, options={}, &block)
      if block_given?
        instance, options = content, instance || {}
        content = capture(&block)
      end

      if options.key?(:admin)
        admin = Trestle.lookup(options.delete(:admin))
      else
        admin = admin_for(instance) || self.admin
      end

      if admin
        link_to(content, admin_url_for(instance, admin: admin), options)
      else
        content
      end
    end

    def admin_url_for(instance, options={})
      admin = Trestle.lookup(options[:admin] || self.admin)
      admin.path(options[:action] || :show, id: admin.to_param(instance)) if admin
    end

    def admin_for(instance)
      Trestle.admins[instance.class.name.underscore.pluralize]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
trestle-0.8.3 app/helpers/trestle/url_helper.rb