50 lines
1.0 KiB
Ruby
50 lines
1.0 KiB
Ruby
class Admin::SnippetsController < ApplicationController
|
|
|
|
layout "admin"
|
|
before_filter :authenticate_user!
|
|
before_filter :find_parent_item
|
|
|
|
def show
|
|
#TODO
|
|
end
|
|
|
|
def new
|
|
@snippet = Snippet.new
|
|
@snippet.parent_name = @parent_item.name
|
|
end
|
|
|
|
def edit
|
|
@snippet = Snippet.find(params[:id])
|
|
end
|
|
|
|
def create
|
|
@snippet = Snippet.new(params[:snippet])
|
|
|
|
if @snippet.save
|
|
flash[:notice] = 'Snippet was successfully created.'
|
|
redirect_to admin_items_url( :parent_name => @snippet.parent_name )
|
|
else
|
|
render :action => "new"
|
|
end
|
|
end
|
|
|
|
def update
|
|
@snippet = Snippet.find(params[:id])
|
|
|
|
if @snippet.update_attributes(params[:snippet])
|
|
flash[:notice] = 'Snippet was successfully updated.'
|
|
redirect_to admin_items_url( :parent_name => @snippet.parent_name )
|
|
else
|
|
render :action => "edit"
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@snippet = Snippet.find(params[:id])
|
|
@snippet.destroy
|
|
|
|
redirect_to admin_items_url( :parent_name => @snippet.parent_name )
|
|
end
|
|
|
|
end
|