51 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Ruby
		
	
	
	
			
		
		
	
	
			51 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Ruby
		
	
	
	
class Admin::SnippetsController < ApplicationController
 | 
						|
  
 | 
						|
  layout "admin"
 | 
						|
  before_filter :authenticate_user!
 | 
						|
  before_filter :find_parent_item
 | 
						|
  before_filter :is_admin?
 | 
						|
  
 | 
						|
  def show
 | 
						|
    #TODO
 | 
						|
  end
 | 
						|
 | 
						|
  def new
 | 
						|
    @snippet = Snippet.new
 | 
						|
    @snippet.parent_id = @parent_item.id
 | 
						|
  end
 | 
						|
 | 
						|
  def edit
 | 
						|
    @snippet = Snippet.find(params[:id])
 | 
						|
  end
 | 
						|
 | 
						|
  def create
 | 
						|
    @snippet = Snippet.new(params[:snippet])
 | 
						|
 | 
						|
    if @snippet.save
 | 
						|
      flash[:notice] = t('admin.create_success_snippet')
 | 
						|
      redirect_to admin_items_url( :parent_id => @snippet.parent_id )
 | 
						|
    else
 | 
						|
      render :action => "new"
 | 
						|
    end
 | 
						|
  end
 | 
						|
 | 
						|
  def update
 | 
						|
    @snippet = Snippet.find(params[:id])
 | 
						|
 | 
						|
    if @snippet.update_attributes(params[:snippet])
 | 
						|
      flash[:notice] = t('admin.update_success_snippet')
 | 
						|
      redirect_to admin_items_url( :parent_id => @snippet.parent_id )
 | 
						|
    else
 | 
						|
      render :action => "edit" 
 | 
						|
    end
 | 
						|
  end
 | 
						|
 | 
						|
  def destroy
 | 
						|
    @snippet = Snippet.find(params[:id])
 | 
						|
    @snippet.destroy
 | 
						|
 | 
						|
    redirect_to admin_items_url( :parent_id => @snippet.parent_id )
 | 
						|
  end
 | 
						|
  
 | 
						|
end
 |