class EquipmentController < ApplicationController before_filter :redirect_if_not_logged_in before_filter :require_ownership_of_equipment, :only => [:show, :edit, :destroy] def index @equipment = Equipment.where(user_id: session[:user]) if @equipment.size == 0 @equipment = [] end @equipment = @equipment.sort { |a, b| a.name.downcase <=> b.name.downcase } respond_to do |format| format.html # index.html.erb format.json { render json: @equipment } end end def show @equipment = Equipment.find(params[:id]) respond_to do |format| format.html # show.html.erb format.json { render json: @equipment } end end def new @equipment = Equipment.new respond_to do |format| format.html # new.html.erb format.json { render json: @equipment } end end def edit @equipment = Equipment.find(params[:id]) end def create @equipment = Equipment.new(params[:equipment]) @equipment.user_id = session[:user] respond_to do |format| if @equipment.save format.html { redirect_to @equipment, notice: 'Equipment was successfully created.' } format.json { render json: @equipment, status: :created, location: @equipment } else format.html { render action: "new" } format.json { render json: @equipment.errors, status: :unprocessable_entity } end end end def update @equipment = Equipment.find(params[:id]) respond_to do |format| if @equipment.update_attributes(params[:equipment]) format.html { redirect_to @equipment, notice: 'Equipment was successfully updated.' } format.json { head :no_content } else format.html { render action: "edit" } format.json { render json: @equipment.errors, status: :unprocessable_entity } end end end def destroy @equipment = Equipment.find(params[:id]) @equipment.destroy respond_to do |format| format.html { redirect_to equipment_list_url } format.json { head :no_content } end end end