Guest User

statuses_controller.rb

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