orbit-basic/app/controllers/admin/snippets_controller.rb

86 lines
2.0 KiB
Ruby

class Admin::SnippetsController < ApplicationController
layout "admin"
# GET /snippets
# GET /snippets.xml
def index
@snippets = Snippet.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @snippets }
end
end
# GET /snippets/1
# GET /snippets/1.xml
def show
@snippet = Snippet.find(params[:id])
redirect_to "/#{@snippet.name}"
end
# GET /snippets/new
# GET /snippets/new.xml
def new
@snippet = Snippet.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @snippets }
end
end
# GET /snippets/1/edit
def edit
@snippet = Snippet.find(params[:id])
end
# POST /snippets
# POST /snippets.xml
def create
@snippet = Snippet.new(params[:snippet])
respond_to do |format|
if @snippet.save
flash[:notice] = 'Snippet was successfully created.'
format.html { redirect_to admin_snippets_url }
format.xml { render :xml => @snippet, :status => :created, :location => @snippets }
else
format.html { render :action => "new" }
format.xml { render :xml => @snippet.errors, :status => :unprocessable_entity }
end
end
end
# PUT /snippets/1
# PUT /snippets/1.xml
def update
@snippet = Snippet.find(params[:id])
respond_to do |format|
if @snippet.update_attributes(params[:snippet])
flash[:notice] = 'Snippet was successfully updated.'
format.html { redirect_to admin_snippets_url }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @snippet.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /snippets/1
# DELETE /snippets/1.xml
def destroy
@snippet = Snippet.find(params[:id])
@snippet.destroy
respond_to do |format|
format.html { redirect_to admin_snippets_url }
format.xml { head :ok }
end
end
end