Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Panel::CategoriesController < ApplicationController
- before_filter :find_users
- # GET /panel/categories
- # GET /panel/categories.xml
- def index
- @panel_categories = Panel::Category.all
- respond_to do |format|
- format.html # index.html.erb
- format.xml { render :xml => @panel_categories }
- end
- end
- # GET /panel/categories/1
- # GET /panel/categories/1.xml
- def show
- @panel_category = Panel::Category.find(params[:id])
- respond_to do |format|
- format.html # show.html.erb
- format.xml { render :xml => @panel_category }
- end
- end
- # GET /panel/categories/new
- # GET /panel/categories/new.xml
- def new
- @panel_category = Panel::Category.new
- respond_to do |format|
- format.html # new.html.erb
- format.xml { render :xml => @panel_category }
- end
- end
- # GET /panel/categories/1/edit
- def edit
- @panel_category = Panel::Category.find(params[:id])
- end
- # POST /panel/categories
- # POST /panel/categories.xml
- def create
- @panel_category = Panel::Category.new(params[:panel_category])
- @panel_category.user_id = current_user[:id]
- respond_to do |format|
- if @panel_category.save
- format.html { redirect_to(@panel_category, :notice => 'Category was successfully created.') }
- format.xml { render :xml => @panel_category, :status => :created, :location => @panel_category }
- else
- format.html { render :action => "new" }
- format.xml { render :xml => @panel_category.errors, :status => :unprocessable_entity }
- end
- end
- end
- # PUT /panel/categories/1
- # PUT /panel/categories/1.xml
- def update
- @panel_category = Panel::Category.find(params[:id])
- respond_to do |format|
- if @panel_category.update_attributes(params[:panel_category])
- format.html { redirect_to(@panel_category, :notice => 'Category was successfully updated.') }
- format.xml { head :ok }
- else
- format.html { render :action => "edit" }
- format.xml { render :xml => @panel_category.errors, :status => :unprocessable_entity }
- end
- end
- end
- # DELETE /panel/categories/1
- # DELETE /panel/categories/1.xml
- def destroy
- @panel_category = Panel::Category.find(params[:id])
- @panel_category.destroy
- respond_to do |format|
- format.html { redirect_to(panel_categories_url) }
- format.xml { head :ok }
- end
- end
- protected
- def find_users
- @users = User.find(:all).map do |user|
- [ user.username, user.id ]
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement