Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

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