def add_to_cart
begin
product = Product.find(params[:id])
# if can not find product id, catch exception, raise error to be
# displayed on 'index' page
rescue ActiveRecord::RecordNotFound
logger.error("Atempt to access invalid product #{params[:id]}")
flash[:notice] = "invalid product"
redirect_to :action => :index
else
# if can find product id, continue to add product to cart
@cart = find_cart
@cart.add_product(product)
end
end
# RHTML code
<% if flash[:notice] -%>
<div id="notice"><%= flash[:notice] %></div>
<% end -%>
## Set these vars up
set :application, "your_appname" # The name of the app
set :user, "your_username" # Your Textdrive username
set :domain, 'your_servername.textdrive.com' # Your domain
set :path, "/users/home/#{user}" # The path to root of your site
set :port, YOUR_PORT # Your port from Textdrive
set :apps_directory, "railsapps" # The directory where you store your rails apps
## Don't have to worry about anything below here
set :repository, "http://url_for.yoursvnrepos.com/svn/#{application}/trunk"
set :svn_username, Proc.new { "your_svn_username --password your_svn_password" }
set :deploy_to, "#{path}/#{apps_directory}/#{application}"
role :web, domain
role :app, domain
role :db, domain, :primary => true
# Space saving by Visi http://blogs.law.harvard.edu/vgondi/about
set :keep_releases, 3
set :checkout, "export"
task :cold_deploy do
transaction do
update_code
symlink
end
run "chmod 755 #{deploy_to}/current/script/spawn"
run "#{deploy_to}/current/script/spawn"
restart
end
task :restart do
run "#{deploy_to}/current/script/process/reaper -a reload"
end
task :after_deploy do
#run "cp #{path}/etc/#{application}.yml #{path}/sites/#{application}/current/config/database.yml"
#setup links to directories in the shared directory
delete "#{current_path}/public/photos", :recursive => true
run "ln -nfs #{shared_path}/photos #{current_path}/public/photos"
end
desc <<-DESC
Removes unused releases from the releases directory. By default, the last 5
releases are retained, but this can be configured with the 'keep_releases'
variable. This will use sudo to do the delete by default, but you can specify
that run should be used by setting the :use_sudo variable to false.
DESC
task :cleanup do
count = (self[:keep_releases] || 5).to_i
if count >= releases.length
logger.important "no old releases to clean up"
else
logger.info "keeping #{count} of #{releases.length} deployed releases"
directories = (releases - releases.last(count)).map { |release|
File.join(releases_path, release) }.join(" ")
delete "#{directories}", :recursive => true
end
end
task :after_setup, :roles=>[:web, :app, :db] do
end