Class: Tenon::ResourcesController
Direct Known Subclasses
AssetsController, CommentsController, ContactsController, EventsController, GalleriesController, PagesController, PostsController, RedirectsController, SimpleResourcesController, TenonCalloutsController, UsersController
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ResourcesController.
5
6
7
8
|
# File 'app/controllers/tenon/resources_controller.rb', line 5
def initialize(*args)
self.class.load_and_authorize_resource(send(:load_options))
super(*args)
end
|
Instance Method Details
#create ⇒ Object
50
51
52
53
54
55
56
57
58
|
# File 'app/controllers/tenon/resources_controller.rb', line 50
def create
self.resource = klass.new(resource_params).decorate
authorize!(:publish, resource)
if resource.save && !request.xhr?
flash[:notice] = "#{human_name} saved successfully."
save_item_version if resource.respond_to?(:versions)
end
respond_with(resource.decorate, location: after_create_path, status: (201 if resource.valid?))
end
|
#destroy ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
|
# File 'app/controllers/tenon/resources_controller.rb', line 60
def destroy
if resource.destroy
respond_with(resource, location: polymorphic_index_path)
else
respond_to do |format|
format.json do
render json: { errors: resource.errors }
end
end
end
end
|
#edit ⇒ Object
31
32
33
34
35
36
37
|
# File 'app/controllers/tenon/resources_controller.rb', line 31
def edit
if params[:version] && resource.respond_to?(:revert)
@item_version = Tenon::ItemVersion.find(params[:version])
resource.revert(@item_version)
end
respond_with(resource)
end
|
#index ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'app/controllers/tenon/resources_controller.rb', line 10
def index
params[:page] = 1 if params[:page].to_i == 0
respond_to do |format|
format.html
format.json do
self.collection = klass.all
self.collection = collection.where(search_args) if params[:q]
self.collection = collection.paginate(per_page: 20, page: params[:page])
self.collection = Tenon::PaginatingDecorator.decorate(collection)
end
end
end
|
#new ⇒ Object
23
24
25
26
27
28
29
|
# File 'app/controllers/tenon/resources_controller.rb', line 23
def new
if params[:version] && resource.respond_to?(:revert)
@item_version = Tenon::ItemVersion.find(params[:version])
resource.revert(@item_version)
end
respond_with(resource)
end
|
#reorder ⇒ Object
72
73
74
75
|
# File 'app/controllers/tenon/resources_controller.rb', line 72
def reorder
self.collection = klass.reorder!(params['item_list'])
respond_with(collection, location: polymorphic_index_path)
end
|
#update ⇒ Object
39
40
41
42
43
44
45
46
47
48
|
# File 'app/controllers/tenon/resources_controller.rb', line 39
def update
authorize!(:publish, resource)
if resource.update_attributes(resource_params)
save_item_version if resource.respond_to?(:versions)
flash[:notice] = "#{human_name} saved successfully." unless request.xhr?
end
self.resource = resource.decorate
respond_with(resource.decorate, location: after_update_path)
end
|