Class: Trek::ResourceController
Instance Method Summary
collapse
#create_success_redirect, #destroy_success_redirect, #success_redirect, #update_success_redirect
Methods included from Notices
#create_notice, #destroy_notice, #update_notice
Methods included from Model
#model, #model_collection, #model_collection_route, #model_element, #model_element_route, #model_intro, #model_objects
Methods included from Hooks
#create_hook, #destroy_hook, #update_hook
Instance Method Details
#create ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'app/controllers/trek/resource_controller.rb', line 27
def create
@object = model.new(object_params)
authorize! @object
create_hook
respond_to do |format|
if @object.save
format.html { redirect_to create_success_redirect, notice: create_notice }
format.json { render :show, status: :created, location: @object }
else
format.html do
flash.now[:alert] = t("admin.errors.message", count: @object.errors.count)
render :new, status: :unprocessable_entity
end
format.json { render json: @object.errors, status: :unprocessable_entity }
end
end
end
|
#destroy ⇒ Object
64
65
66
67
68
69
70
71
72
73
|
# File 'app/controllers/trek/resource_controller.rb', line 64
def destroy
@object.destroy
destroy_hook
respond_to do |format|
format.html { redirect_to destroy_success_redirect, notice: destroy_notice }
format.json { head :no_content }
end
end
|
#edit ⇒ Object
24
25
|
# File 'app/controllers/trek/resource_controller.rb', line 24
def edit
end
|
#index ⇒ Object
10
11
12
13
14
|
# File 'app/controllers/trek/resource_controller.rb', line 10
def index
@objects = authorized_scope(model_objects)
@objects = @objects.ordered if @objects.respond_to?(:ordered)
authorize! @objects
end
|
#new ⇒ Object
19
20
21
22
|
# File 'app/controllers/trek/resource_controller.rb', line 19
def new
@object = model.new
authorize! @object
end
|
#show ⇒ Object
16
17
|
# File 'app/controllers/trek/resource_controller.rb', line 16
def show
end
|
#update ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'app/controllers/trek/resource_controller.rb', line 47
def update
update_hook
respond_to do |format|
if @object.update(object_params)
format.html { redirect_to update_success_redirect, notice: update_notice }
format.json { render :show, status: :ok, location: @object }
else
format.html do
flash.now[:alert] = t("admin.errors.message", count: @object.errors.count)
render :edit, status: :unprocessable_entity
end
format.json { render json: @object.errors, status: :unprocessable_entity }
end
end
end
|