Class: Trestle::Resource::Controller

Inherits:
Admin::Controller show all
Defined in:
lib/trestle/resource/controller.rb

Instance Method Summary collapse

Methods inherited from Admin::Controller

controller_path

Instance Method Details

#createObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/trestle/resource/controller.rb', line 12

def create
  self.instance = admin.build_instance(admin.permitted_params(params))

  if admin.save_instance(instance)
    flash[:message] = flash_message("success.create", default: "The %{model_name} was successfully created.")
    redirect_to action: :show, id: admin.to_param(instance)
  else
    flash.now[:error] = flash_message("failure.create", default: "Please correct the errors below.")
    render "new"
  end
end

#destroyObject



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/trestle/resource/controller.rb', line 45

def destroy
  self.instance = admin.find_instance(params)

  if admin.delete_instance(instance)
    flash[:message] = flash_message("success.destroy", default: "The %{model_name} was successfully deleted.")
  else
    flash[:error] = flash_message("failure.destroy", default: "Could not delete %{model_name}.")
  end

  redirect_to action: :index
end

#editObject



28
29
30
# File 'lib/trestle/resource/controller.rb', line 28

def edit
  self.instance = admin.find_instance(params)
end

#indexObject



4
5
6
# File 'lib/trestle/resource/controller.rb', line 4

def index
  self.collection = admin.prepare_collection(params)
end

#newObject



8
9
10
# File 'lib/trestle/resource/controller.rb', line 8

def new
  self.instance = admin.build_instance
end

#showObject



24
25
26
# File 'lib/trestle/resource/controller.rb', line 24

def show
  self.instance = admin.find_instance(params)
end

#updateObject



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/trestle/resource/controller.rb', line 32

def update
  self.instance = admin.find_instance(params)
  admin.update_instance(instance, admin.permitted_params(params))

  if admin.save_instance(instance)
    flash[:message] = flash_message("success.update", default: "The %{model_name} was successfully updated.")
    redirect_to action: :show, id: admin.to_param(instance)
  else
    flash.now[:error] = flash_message("failure.update", default: "Please correct the errors below.")
    render "show"
  end
end