Skip to content

Instantly share code, notes, and snippets.

@charly
Created August 19, 2009 07:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charly/170216 to your computer and use it in GitHub Desktop.
Save charly/170216 to your computer and use it in GitHub Desktop.
#route.rb
map.resources "orders", order_hash do |order|
order.resource "invoice"
order.resource "payment", :new => {"express" => :get}
end
#map.resoures "payments" # not in use anymore !
#payments_controller.rb
before_filter :require_order
def show
@payment = @order.payment
end
#order_module.rb
module OrderModule #included in application_controller
def require_order
unless find_and_set_current_order
flash[:notice]= "INVALID URL : the order you were trying to reach doesn't belong to your account"
redirect_to "/account"
return false
end
end
def find_order
@order = current_user.orders.find_by_id(params[:order_id] || params[:id])
end
def set_current_order
@order && ( self.current_order==@order || self.current_cart= (self.current_order= @order).assets )
end
def find_and_set_current_order
find_order && set_current_order
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment