mirror of
https://github.com/indentlabs/notebook.git
synced 2025-10-26 11:19:22 +00:00
81 lines
2.0 KiB
Ruby
81 lines
2.0 KiB
Ruby
class LocationsController < ApplicationController
|
|
before_filter :redirect_if_not_logged_in
|
|
before_filter :require_ownership_of_location, :only => [:show, :edit, :destroy]
|
|
|
|
def index
|
|
@locations = Location.where(user_id: session[:user])
|
|
|
|
if @locations.size == 0
|
|
@locations = []
|
|
end
|
|
|
|
@locations = @locations.sort { |a, b| a.name.downcase <=> b.name.downcase }
|
|
|
|
respond_to do |format|
|
|
format.html # index.html.erb
|
|
format.json { render json: @locations }
|
|
end
|
|
end
|
|
|
|
def show
|
|
@location = Location.find(params[:id])
|
|
|
|
respond_to do |format|
|
|
format.html # show.html.erb
|
|
format.json { render json: @location }
|
|
end
|
|
end
|
|
|
|
def new
|
|
@location = Location.new
|
|
|
|
respond_to do |format|
|
|
format.html # new.html.erb
|
|
format.json { render json: @location }
|
|
end
|
|
end
|
|
|
|
def edit
|
|
@location = Location.find(params[:id])
|
|
end
|
|
|
|
def create
|
|
@location = Location.new(params[:location])
|
|
@location.user_id = session[:user]
|
|
|
|
respond_to do |format|
|
|
if @location.save
|
|
format.html { redirect_to @location, notice: 'Location was successfully created.' }
|
|
format.json { render json: @location, status: :created, location: @location }
|
|
else
|
|
format.html { render action: "new" }
|
|
format.json { render json: @location.errors, status: :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
def update
|
|
@location = Location.find(params[:id])
|
|
|
|
respond_to do |format|
|
|
if @location.update_attributes(params[:location])
|
|
format.html { redirect_to @location, notice: 'Location was successfully updated.' }
|
|
format.json { head :no_content }
|
|
else
|
|
format.html { render action: "edit" }
|
|
format.json { render json: @location.errors, status: :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@location = Location.find(params[:id])
|
|
@location.destroy
|
|
|
|
respond_to do |format|
|
|
format.html { redirect_to location_list_url }
|
|
format.json { head :no_content }
|
|
end
|
|
end
|
|
end
|