summaryrefslogtreecommitdiff
path: root/app/controllers/parking_stalls_controller.rb
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-02-16 11:10:02 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-02-16 11:10:02 +0100
commit5d8ce5f4775ac8bc5f523964e6e36f63ff3c4683 (patch)
tree49ed889b1d10cda98c475f3453abff1b97afb4e7 /app/controllers/parking_stalls_controller.rb
parentc9066760fd1f5f2f892ce2be5cf2a83bb5210246 (diff)
parent55784bcffc0678ce6102c0b81447434a8030ebd2 (diff)
Merge branch 'develop'5.1-beta5
Diffstat (limited to 'app/controllers/parking_stalls_controller.rb')
-rw-r--r--app/controllers/parking_stalls_controller.rb69
1 files changed, 69 insertions, 0 deletions
diff --git a/app/controllers/parking_stalls_controller.rb b/app/controllers/parking_stalls_controller.rb
new file mode 100644
index 0000000..d1bc0c7
--- /dev/null
+++ b/app/controllers/parking_stalls_controller.rb
@@ -0,0 +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
+ end
+
+ def show
+ end
+
+ def new
+ @parking_stall.lot = 'default'
+ @parking_stall.name = ParkingStall.order(:name).last.try(:name).to_i + 1
+ end
+
+ def create
+ @parking_stall = @parent.parking_stalls.build(params[:parking_stall])
+ if @parking_stall.save
+ redirect_to [@parent, @parking_stall], :notice => t('parking_stalls.controller.successfuly_created')
+ else
+ render :new
+ end
+ end
+
+ def edit
+ end
+
+ def update
+ if @parking_stall.update_attributes(params[:parking_stall])
+ redirect_to [@parent, @parking_stall], :notice => t('parking_stalls.controller.successfuly_updated')
+ else
+ render :edit
+ end
+ end
+
+ def destroy
+ @parking_stall.destroy
+ 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