Module: E9Rails::Helpers::ResourceLinks::HelperMethods
- Defined in:
- lib/e9_rails/helpers/resource_links.rb
Instance Method Summary collapse
- #link_to_collection(resource, options = {}) ⇒ Object
- #link_to_destroy_resource(resource, options = {}) ⇒ Object
- #link_to_edit_resource(resource, options = {}) ⇒ Object
- #link_to_new_resource(resource, options = {}) ⇒ Object
- #link_to_resource(resource, options = {}) ⇒ Object
- #link_to_show_resource(resource, options = {}) ⇒ Object
- #parent ⇒ Object
Instance Method Details
#link_to_collection(resource, options = {}) ⇒ Object
85 86 87 |
# File 'lib/e9_rails/helpers/resource_links.rb', line 85 def link_to_collection(resource, = {}) link_to_resource(resource, .merge(:action => :index)) end |
#link_to_destroy_resource(resource, options = {}) ⇒ Object
81 82 83 |
# File 'lib/e9_rails/helpers/resource_links.rb', line 81 def link_to_destroy_resource(resource, = {}) link_to_resource(resource, .merge(:action => :destroy)) end |
#link_to_edit_resource(resource, options = {}) ⇒ Object
73 74 75 |
# File 'lib/e9_rails/helpers/resource_links.rb', line 73 def link_to_edit_resource(resource, = {}) link_to_resource(resource, .merge(:action => :edit)) end |
#link_to_new_resource(resource, options = {}) ⇒ Object
77 78 79 |
# File 'lib/e9_rails/helpers/resource_links.rb', line 77 def link_to_new_resource(resource, = {}) link_to_resource(resource, .merge(:action => :new)) end |
#link_to_resource(resource, options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/e9_rails/helpers/resource_links.rb', line 14 def link_to_resource(resource, = {}) .symbolize_keys! = .slice!(:scope, :action, :method, :remote, :confirm, :class) klass = resource.is_a?(Class) ? resource : resource.class action = (.delete(:action) || :show).to_sym if klass == resource && ![:index, :new].member?(action) action = :index end scopes = [*([:scope] || @route_scope), parent].compact path = case action when :new; new_polymorphic_path(scopes << klass, ) when :edit; edit_polymorphic_path(scopes << resource, ) when :index; polymorphic_path(scopes << klass, ) else polymorphic_path(scopes << resource, ) end mn = klass.model_name = { :model => mn.human, :models => mn.human.pluralize, :collection => mn.collection, :element => mn.element } if action == :destroy defaults = klass.lookup_ancestors.map {|k| :"#{klass.i18n_scope}.links.#{k.model_name.underscore}.confirm_destroy" } << :"#{klass.i18n_scope}.links.confirm_destroy" [:method] = :delete .reverse_merge!({ :remote => true, :confirm => I18n.t(defaults.shift, .merge(:default => defaults)) }) end # # Mimic ActiveModel's lookup chain for attributes # defaults = klass.lookup_ancestors.map do |k| :"#{klass.i18n_scope}.links.#{k.model_name.underscore}.#{action}" end defaults << :"#{klass.i18n_scope}.links.#{action}" defaults << action.to_s.humanize link_to I18n.t(defaults.shift, .merge(:default => defaults)), path, end |
#link_to_show_resource(resource, options = {}) ⇒ Object
69 70 71 |
# File 'lib/e9_rails/helpers/resource_links.rb', line 69 def link_to_show_resource(resource, = {}) link_to_resource(resource, .merge(:action => :show)) end |
#parent ⇒ Object
10 11 12 |
# File 'lib/e9_rails/helpers/resource_links.rb', line 10 def parent controller.parent rescue nil end |