Advertisement
Guest User

Untitled

a guest
Mar 13th, 2011
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.56 KB | None | 0 0
  1. class Panel::CategoriesController < ApplicationController
  2.   before_filter :find_users
  3.  
  4.   # GET /panel/categories
  5.   # GET /panel/categories.xml
  6.   def index
  7.     @panel_categories = Panel::Category.all
  8.  
  9.     respond_to do |format|
  10.       format.html # index.html.erb
  11.       format.xml  { render :xml => @panel_categories }
  12.     end
  13.   end
  14.  
  15.   # GET /panel/categories/1
  16.   # GET /panel/categories/1.xml
  17.   def show
  18.     @panel_category = Panel::Category.find(params[:id])
  19.  
  20.     respond_to do |format|
  21.       format.html # show.html.erb
  22.       format.xml  { render :xml => @panel_category }
  23.     end
  24.   end
  25.  
  26.   # GET /panel/categories/new
  27.   # GET /panel/categories/new.xml
  28.   def new
  29.     @panel_category = Panel::Category.new
  30.  
  31.     respond_to do |format|
  32.       format.html # new.html.erb
  33.       format.xml  { render :xml => @panel_category }
  34.     end
  35.   end
  36.  
  37.   # GET /panel/categories/1/edit
  38.   def edit
  39.     @panel_category = Panel::Category.find(params[:id])
  40.   end
  41.  
  42.   # POST /panel/categories
  43.   # POST /panel/categories.xml
  44.   def create
  45.     @panel_category = Panel::Category.new(params[:panel_category])
  46.     @panel_category.user_id = current_user[:id]
  47.  
  48.     respond_to do |format|
  49.       if @panel_category.save
  50.         format.html { redirect_to(@panel_category, :notice => 'Category was successfully created.') }
  51.         format.xml  { render :xml => @panel_category, :status => :created, :location => @panel_category }
  52.       else
  53.         format.html { render :action => "new" }
  54.         format.xml  { render :xml => @panel_category.errors, :status => :unprocessable_entity }
  55.       end
  56.     end
  57.   end
  58.  
  59.   # PUT /panel/categories/1
  60.   # PUT /panel/categories/1.xml
  61.   def update
  62.     @panel_category = Panel::Category.find(params[:id])
  63.  
  64.     respond_to do |format|
  65.       if @panel_category.update_attributes(params[:panel_category])
  66.         format.html { redirect_to(@panel_category, :notice => 'Category was successfully updated.') }
  67.         format.xml  { head :ok }
  68.       else
  69.         format.html { render :action => "edit" }
  70.         format.xml  { render :xml => @panel_category.errors, :status => :unprocessable_entity }
  71.       end
  72.     end
  73.   end
  74.  
  75.   # DELETE /panel/categories/1
  76.   # DELETE /panel/categories/1.xml
  77.   def destroy
  78.     @panel_category = Panel::Category.find(params[:id])
  79.     @panel_category.destroy
  80.  
  81.     respond_to do |format|
  82.       format.html { redirect_to(panel_categories_url) }
  83.       format.xml  { head :ok }
  84.     end
  85.   end
  86.  
  87.   protected
  88.     def find_users
  89.         @users = User.find(:all).map do |user|
  90.             [ user.username, user.id ]
  91.         end
  92.     end
  93. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement