forked from locomotivecms/engine
/
snippets_controller.rb
40 lines (32 loc) · 1.07 KB
/
snippets_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
module Locomotive
module Api
class SnippetsController < BaseController
load_and_authorize_resource :class => Locomotive::Snippet
def index
@snippets = current_site.snippets.order_by([[:name, :asc]])
respond_with(@snippets)
end
def show
@snippet = current_site.snippets.find(params[:id])
respond_with @snippet
end
def create
@snippet = current_site.snippets.new
@snippet_presenter = @snippet.to_presenter
@snippet_presenter.update_attributes(params[:snippet])
respond_with @snippet, :location => main_app.locomotive_api_snippets_url
end
def update
@snippet = current_site.snippets.find(params[:id])
@snippet_presenter = @snippet.to_presenter
@snippet_presenter.update_attributes(params[:snippet])
respond_with @snippet, :location => main_app.locomotive_api_snippets_url
end
def destroy
@snippet = current_site.snippets.find(params[:id])
@snippet.destroy
respond_with @snippet
end
end
end
end