Module: InheritedTemplates::ActionView::Helpers

Defined in:
lib/inherited_templates/action_view/helpers.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/inherited_templates/action_view/helpers.rb', line 4

def self.included(base)
  base.class_eval do
    def resource_link(action, r = nil)
      case action
        when :index
          link_to(
            t("#{resource_collection_name}.action.index", :default => "Back"),
            polymorphic_path(controller_name)
          ).html_safe
        when :new
          link_to(
            t("#{resource_collection_name}.action.new", :default => "New"),
            new_polymorphic_path(controller_name.singularize)
          ).html_safe
        when :show
          link_to(
            t("#{resource_collection_name}.action.show", :default => "Show"),
            polymorphic_path(r)
          ).html_safe
        when :edit
          link_to(
            t("#{resource_collection_name}.action.edit", :default => "Edit"),
            edit_polymorphic_path(r)
          ).html_safe
        when :destroy
          link_to(
            t("#{resource_collection_name}.action.destroy", :default => "Destroy"),
            polymorphic_path(r),
            { :confirm => t("#{resource_collection_name}.confirm.destroy", :default => "Are you sure?"), :method => :delete }
          ).html_safe
      end
    end
  end
end