Module: Patternist::Controllers::ActionPack::Restful::InstanceMethods

Defined in:
lib/patternist/controllers/actionpack/restful.rb

Overview

Instance methods implementing RESTful actions

Instance Method Summary collapse

Instance Method Details

#createObject

Creates a new resource



42
43
44
45
46
47
48
49
50
51
# File 'lib/patternist/controllers/actionpack/restful.rb', line 42

def create
  self.resource_instance = resource_class.new(resource_params)

  format_response(resource,
                  notice: "#{resource_class_name} was successfully created.",
                  status: :created,
                  on_error_render: :new) do
    create_resource
  end
end

#destroyObject

Destroys an existing resource



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/patternist/controllers/actionpack/restful.rb', line 66

def destroy
  self.resource_instance = find_resource

  notice = "#{resource_class_name} was successfully destroyed."
  format_response(resource,
                  notice: notice,
                  status: :see_other,
                  on_error_render: :show,
                  formats: {
                    html: -> { redirect_to resource_class, notice: notice },
                    json: -> { head :no_content }
                  }) do
    destroy_resource
  end
end

#editObject

Prepares a resource for editing



30
31
32
33
# File 'lib/patternist/controllers/actionpack/restful.rb', line 30

def edit
  self.resource_instance = find_resource
  yield if block_given?
end

#indexObject

Lists all resources



21
# File 'lib/patternist/controllers/actionpack/restful.rb', line 21

def index = self.collection_instance = collection

#newObject

Initializes a new resource



36
37
38
39
# File 'lib/patternist/controllers/actionpack/restful.rb', line 36

def new
  self.resource_instance = resource_class.new
  yield if block_given?
end

#showObject

Shows a single resource



24
25
26
27
# File 'lib/patternist/controllers/actionpack/restful.rb', line 24

def show
  self.resource_instance = find_resource
  yield if block_given?
end

#updateObject

Updates an existing resource



54
55
56
57
58
59
60
61
62
63
# File 'lib/patternist/controllers/actionpack/restful.rb', line 54

def update
  self.resource_instance = find_resource

  format_response(resource,
                  notice: "#{resource_class_name} was successfully updated.",
                  status: :ok,
                  on_error_render: :edit) do
    update_resource
  end
end