Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

trainings_controller.rb

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