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

places_controller.rb

By: endorama on May 22nd, 2013  |  syntax: Ruby  |  size: 2.19 KB  |  views: 7  |  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 PlacesController < ApplicationController
  2.   before_filter :authenticate_user!, :only => [ :create, :destroy, :edit, :new, :update]
  3.  
  4.   add_breadcrumb I18n.t('breadcrumbs.home'), :root_path
  5.   add_breadcrumb I18n.t('breadcrumbs.places'), :places_path
  6.  
  7.   # GET /places
  8.   # GET /places.json
  9.   def index
  10.     @places = Place.all
  11.  
  12.     respond_to do |format|
  13.       format.html # index.html.erb
  14.       format.json { render json: @places }
  15.     end
  16.   end
  17.  
  18.   # GET /places/1
  19.   # GET /places/1.json
  20.   def show
  21.     @place = Place.find(params[:id])
  22.  
  23.     add_breadcrumb "#{@place}", :place_path
  24.  
  25.     respond_to do |format|
  26.       format.html # show.html.erb
  27.       format.json { render json: @place }
  28.     end
  29.   end
  30.  
  31.   # GET /places/new
  32.   # GET /places/new.json
  33.   def new
  34.     @place = Place.new
  35.  
  36.     respond_to do |format|
  37.       format.html # new.html.erb
  38.       format.json { render json: @place }
  39.     end
  40.   end
  41.  
  42.   # GET /places/1/edit
  43.   def edit
  44.     @place = Place.find(params[:id])
  45.   end
  46.  
  47.   # POST /places
  48.   # POST /places.json
  49.   def create
  50.     @place = Place.new(params[:place])
  51.  
  52.     respond_to do |format|
  53.       if @place.save
  54.         format.html { redirect_to @place, notice: 'Place was successfully created.' }
  55.         format.json { render json: @place, status: :created, location: @place }
  56.       else
  57.         format.html { render action: "new" }
  58.         format.json { render json: @place.errors, status: :unprocessable_entity }
  59.       end
  60.     end
  61.   end
  62.  
  63.   # PUT /places/1
  64.   # PUT /places/1.json
  65.   def update
  66.     @place = Place.find(params[:id])
  67.  
  68.     respond_to do |format|
  69.       if @place.update_attributes(params[:place])
  70.         format.html { redirect_to @place, notice: 'Place was successfully updated.' }
  71.         format.json { head :no_content }
  72.       else
  73.         format.html { render action: "edit" }
  74.         format.json { render json: @place.errors, status: :unprocessable_entity }
  75.       end
  76.     end
  77.   end
  78.  
  79.   # DELETE /places/1
  80.   # DELETE /places/1.json
  81.   def destroy
  82.     @place = Place.find(params[:id])
  83.     @place.destroy
  84.  
  85.     respond_to do |format|
  86.       format.html { redirect_to places_url }
  87.       format.json { head :no_content }
  88.     end
  89.   end
  90. end
clone this paste RAW Paste Data