summaryrefslogtreecommitdiff
path: root/app/controllers/parking_stalls_controller.rb
diff options
context:
space:
mode:
authorspag <spag@golwen.net>2013-02-12 15:53:49 +0100
committerspag <spag@golwen.net>2013-02-12 15:53:49 +0100
commit36d1a38594361dcd021c23ae9c5040a37d0918df (patch)
tree15ebad678743935103e441bc54609ef9c58801a4 /app/controllers/parking_stalls_controller.rb
parentfbdb5dca9b3979010b87b16fcb3bf9410c453e91 (diff)
make parking stall child of user/tenant
Diffstat (limited to 'app/controllers/parking_stalls_controller.rb')
-rw-r--r--app/controllers/parking_stalls_controller.rb48
1 files changed, 38 insertions, 10 deletions
diff --git a/app/controllers/parking_stalls_controller.rb b/app/controllers/parking_stalls_controller.rb
index 42931ed..d1bc0c7 100644
--- a/app/controllers/parking_stalls_controller.rb
+++ b/app/controllers/parking_stalls_controller.rb
@@ -1,41 +1,69 @@
class ParkingStallsController < ApplicationController
+
+ load_resource :tenant
+ load_resource :user
+ load_and_authorize_resource :parking_stall, :through => [:user, :tenant ]
+
+ before_filter :set_and_authorize_parent
+ before_filter :spread_breadcrumbs
+
def index
- @parking_stalls = ParkingStall.all
end
def show
- @parking_stall = ParkingStall.find(params[:id])
end
def new
- @parking_stall = ParkingStall.new
+ @parking_stall.lot = 'default'
+ @parking_stall.name = ParkingStall.order(:name).last.try(:name).to_i + 1
end
def create
- @parking_stall = ParkingStall.new(params[:parking_stall])
+ @parking_stall = @parent.parking_stalls.build(params[:parking_stall])
if @parking_stall.save
- redirect_to @parking_stall, :notice => t('parking_stalls.controller.successfuly_created')
+ redirect_to [@parent, @parking_stall], :notice => t('parking_stalls.controller.successfuly_created')
else
render :new
end
end
def edit
- @parking_stall = ParkingStall.find(params[:id])
end
def update
- @parking_stall = ParkingStall.find(params[:id])
if @parking_stall.update_attributes(params[:parking_stall])
- redirect_to @parking_stall, :notice => t('parking_stalls.controller.successfuly_updated')
+ redirect_to [@parent, @parking_stall], :notice => t('parking_stalls.controller.successfuly_updated')
else
render :edit
end
end
def destroy
- @parking_stall = ParkingStall.find(params[:id])
@parking_stall.destroy
- redirect_to parking_stalls_url, :notice => t('parking_stalls.controller.successfuly_destroyed')
+ m = method( :"#{@parent.class.name.underscore}_parking_stalls_url" )
+ redirect_to m.(@parent), :notice => t('parking_stalls.controller.successfuly_destroyed')
+ end
+
+ private
+ def set_and_authorize_parent
+ @parent = @user || @tenant
+ authorize! :read, @parent
+ end
+
+ def spread_breadcrumbs
+ if @user
+ add_breadcrumb t("users.index.page_title"), tenant_users_path(@user.current_tenant)
+ add_breadcrumb @user, tenant_user_path(@user.current_tenant, @user)
+ add_breadcrumb t("parking_stalls.index.page_title"), user_parking_stalls_path(@user)
+ if @parking_stall && !@parking_stall.new_record?
+ add_breadcrumb @parking_stall, user_parking_stall_path(@user, @parking_stall)
+ end
+ end
+ if @tenant
+ add_breadcrumb t("parking_stalls.index.page_title"), tenant_parking_stalls_path(@tenant)
+ if @parking_stall && !@parking_stall.new_record?
+ add_breadcrumb @parking_stall, tenant_parking_stall_path(@tenant, @parking_stall)
+ end
+ end
end
end