Class: DynamicController::Responder

Inherits:
Object
  • Object
show all
Defined in:
lib/dynamic_controller/responder.rb

Instance Method Summary collapse

Constructor Details

#initialize(controller) ⇒ Responder

Returns a new instance of Responder.



4
5
6
# File 'lib/dynamic_controller/responder.rb', line 4

def initialize(controller)
  @controller = controller
end

Instance Method Details

#createObject



30
31
32
33
34
# File 'lib/dynamic_controller/responder.rb', line 30

def create
  action :create,
         html: Proc.new { redirect_to action: :show, id: model.id },
         json: Proc.new { render json: model, status: :created }
end

#destroyObject



42
43
44
45
46
# File 'lib/dynamic_controller/responder.rb', line 42

def destroy
  action :destroy,
         html: Proc.new { redirect_to action: :index },
         json: Proc.new { head :no_content }
end

#editObject



25
26
27
28
# File 'lib/dynamic_controller/responder.rb', line 25

def edit
  action :edit,
         html: Proc.new {}
end

#indexObject



8
9
10
11
12
# File 'lib/dynamic_controller/responder.rb', line 8

def index
  action :index,
         html: Proc.new {},
         json: Proc.new { render json: collection }
end

#newObject



20
21
22
23
# File 'lib/dynamic_controller/responder.rb', line 20

def new
  action :new,
         html: Proc.new {}
end

#showObject



14
15
16
17
18
# File 'lib/dynamic_controller/responder.rb', line 14

def show
  action :show,
         html: Proc.new {},
         json: Proc.new { render json: model }
end

#updateObject



36
37
38
39
40
# File 'lib/dynamic_controller/responder.rb', line 36

def update
  action :update,
         html: Proc.new { redirect_to action: :show, id: model.id },
         json: Proc.new { head :no_content }
end