This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jun 9th, 2010  |  syntax: Rails  |  size: 2.08 KB  |  views: 98  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. class QuestionsController < ApplicationController
  2.   before_filter :find_question, :only => [:show, :edit, :update, :destroy]
  3.  
  4.   # GET /questions
  5.   # GET /questions.xml
  6.   def index
  7.  
  8.     respond_to do |wants|
  9.       wants.html # index.html.erb
  10.       wants.xml  { render :xml => @assessments }
  11.     end
  12.   end
  13.  
  14.   # GET /questions/1
  15.   # GET /questions/1.xml
  16.   def show
  17.     respond_to do |wants|
  18.       wants.html # show.html.erb
  19.       wants.xml  { render :xml => @question }
  20.     end
  21.   end
  22.  
  23.   # GET /questions/new
  24.   # GET /questions/new.xml
  25.   def new
  26.     @question = Question.new
  27.  
  28.     respond_to do |wants|
  29.       wants.html # new.html.erb
  30.       wants.xml  { render :xml => @question }
  31.     end
  32.   end
  33.  
  34.   # GET /questions/1/edit
  35.   def edit
  36.   end
  37.  
  38.   # POST /questions
  39.   # POST /questions.xml
  40.   def create
  41.     @question = Question.new(params[:question])
  42.  
  43.     respond_to do |wants|
  44.       if @question.save
  45.         flash[:notice] = 'Question was successfully created.'
  46.         wants.html { redirect_to(@question) }
  47.         wants.xml  { render :xml => @question,
  48.                             :status => :created,
  49.                             :location => @question }
  50.       else
  51.         wants.html { render :action => "new" }
  52.         wants.xml  { render :xml => @question.errors,
  53.                             :status => :unprocessable_entity }
  54.       end
  55.     end
  56.   end
  57.  
  58.   # PUT /questions/1
  59.   # PUT /questions/1.xml
  60.   def update
  61.     respond_to do |wants|
  62.       if @question.update_attributes(params[:question])
  63.         flash[:notice] = 'Question was successfully updated.'
  64.         wants.html { redirect_to(@question) }
  65.         wants.xml  { head :ok }
  66.       else
  67.         wants.html { render :action => "edit" }
  68.         wants.xml  { render :xml => @question.errors,
  69.                             :status => :unprocessable_entity }
  70.       end
  71.     end
  72.   end
  73.  
  74.   # DELETE /questions/1
  75.   # DELETE /questions/1.xml
  76.   def destroy
  77.     @question.destroy
  78.  
  79.     respond_to do |wants|
  80.       wants.html { redirect_to(questions_url) }
  81.       wants.xml  { head :ok }
  82.     end
  83.   end
  84.  
  85.   private
  86.     def find_question
  87.       @question = Question.find(params[:id])
  88.     end
  89.  
  90. end
clone this paste RAW Paste Data