2010-05-10 22:39:52 +00:00
|
|
|
module Admin
|
|
|
|
class SnippetsController < BaseController
|
2010-05-02 23:33:17 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
sections 'settings'
|
2010-05-02 23:33:17 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
def index
|
|
|
|
@snippets = current_site.snippets
|
|
|
|
end
|
2010-05-02 23:33:17 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
def new
|
|
|
|
@snippet = current_site.snippets.build
|
|
|
|
end
|
2010-05-02 23:33:17 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
def edit
|
|
|
|
@snippet = current_site.snippets.find(params[:id])
|
|
|
|
end
|
2010-05-02 23:33:17 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
def create
|
|
|
|
@snippet = current_site.snippets.build(params[:snippet])
|
2010-05-02 23:33:17 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
if @snippet.save
|
|
|
|
flash_success!
|
|
|
|
redirect_to edit_admin_snippet_url(@snippet)
|
|
|
|
else
|
|
|
|
flash_error!
|
|
|
|
render :action => 'new'
|
|
|
|
end
|
2010-05-02 23:33:17 +00:00
|
|
|
end
|
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
def update
|
|
|
|
@snippet = current_site.snippets.find(params[:id])
|
2010-05-02 23:33:17 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
if @snippet.update_attributes(params[:snippet])
|
|
|
|
flash_success!
|
|
|
|
redirect_to edit_admin_snippet_url(@snippet)
|
|
|
|
else
|
|
|
|
flash_error!
|
|
|
|
render :action => "edit"
|
|
|
|
end
|
2010-05-02 23:33:17 +00:00
|
|
|
end
|
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
def destroy
|
|
|
|
@snippet = current_site.snippets.find(params[:id])
|
2010-05-02 23:33:17 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
begin
|
|
|
|
@snippet.destroy
|
|
|
|
flash_success!
|
|
|
|
rescue Exception => e
|
|
|
|
flash[:error] = e.to_s
|
|
|
|
end
|
2010-05-02 23:33:17 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
redirect_to admin_snippets_url
|
|
|
|
end
|
2010-05-02 23:33:17 +00:00
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
end
|
2010-05-02 23:33:17 +00:00
|
|
|
end
|