Skip to content

Instantly share code, notes, and snippets.

@pyrat
Created February 26, 2009 10:57
Show Gist options
  • Save pyrat/70794 to your computer and use it in GitHub Desktop.
Save pyrat/70794 to your computer and use it in GitHub Desktop.
require 'order_session'
class AddressesController < ApplicationController
include Pyrat::Session
before_filter :get_order
# ssl_required :new, :create, :edit, :update
layout 'standard'
# this brings up the form for creating new addresses
def new
if @order.address
@address = @order.address
else
@address = Address.new
end
if params[:id].to_i==999 then
@shippings = Shipping.find(:all, :conditions=>["id > 1"])
@shipid = 2
else
@shippings = Shipping.find(:all)
@shipid = 1
end
end
# create both addresses
def create
if (params[:shipping_id].nil?)
@order.shipping_id=2;
@order.save
else
@order.shipping_id=params[:shipping_id];
@order.save
end
@address = Address.new(params[:address].merge(:order_id => @order.id))
if @address.save
flash[:message] = "Successfully saved address details."
redirect_to order_confirm_url
else
@shippings = Shipping.find(:all)
render :action => :new
end
end
def edit
@address = @order.address
render :action => :new
end
def update
@address = @order.address
if @address.update_attributes(params[:address])
flash[:message] = "Successfully updated address details"
redirect_to order_confirm_url
else
render :action => :new
end
end
private
def get_order
@order = get_order_from_session(:redirect => true)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment