Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 3 support #3

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
be0ea40
Upgraded to Rails 3
remear Nov 22, 2011
eada377
Used foreigner gem for database foreign keys
remear Nov 27, 2011
9a5a6d0
Fixed routes
remear Nov 27, 2011
a460d88
Changed content_for to yield
remear Nov 27, 2011
09fcc8f
Disabled ssl redirect and authentication check for now
remear Nov 27, 2011
05a2fa2
Attempt to fix routes since the rails upgrade plugin obviously was ep…
remear Nov 28, 2011
60cf28a
Disable SSL redirect in orders for now
remear Nov 28, 2011
061e220
Added uuidtools gem
remear Jan 7, 2012
7405f70
Use Rails 3 style closing tags
remear Jan 7, 2012
648c90f
Remove frozen Rails version
remear Jan 7, 2012
4ad755b
Fixed paypal.yml config eval
remear Jan 7, 2012
a2b352d
Changed unique_id calls to use uuid
remear Jan 7, 2012
91b245e
Fixed more routes
remear Jan 7, 2012
d78fb52
Use updated paypal config
remear Jan 7, 2012
ad7c1d9
Updated README with Rails 3 requirement information
remear Jan 7, 2012
7132ca9
link_to_remote converted to Rails 3 link_to :remote => true
Jan 7, 2012
c34fc3b
Replaced link_to_remote with Rails 3 link_to remote: true
Jan 7, 2012
77b38db
Deprecation warnings have been resolved.
Jan 7, 2012
cb08989
Merge branch 'master' of https://github.com/remear/potionstore
remear Jan 7, 2012
f6f7f16
Upgraded to Rails 3.2.2 and compatible gems
remear Mar 5, 2012
27b03b3
verify is no longer part of Rails 3
remear Mar 5, 2012
020e342
Fixed references to RAILS_ROOT
remear Mar 5, 2012
35110dc
html_safe order failure reason
remear Mar 5, 2012
6135ac7
debug_rjs is no longer part of Rails 3
remear Mar 5, 2012
b3a2557
Reenable order SSL redirect
remear Mar 6, 2012
961fc58
request.request_uri no longer exists in Rails 3. Use request.url
remear Mar 6, 2012
e74efe0
Fixed admin order view date formatting
remear Mar 6, 2012
3037e76
Updated README
remear Mar 6, 2012
ea06184
Merge updates from Rails 3 from Ben Mills and Evan Sparkman
hemancuso Mar 19, 2012
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 12 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
source 'http://rubygems.org'

gem 'rails', '3.2.2'
gem 'foreigner'
gem "google4r-checkout", "~> 1.1.0"
gem "money", "~> 4.0.1"
gem 'mysql2', '~> 0.3.0'
gem 'uuidtools'
gem "xml-simple", "~> 1.1.1"
gem 'will_paginate'
gem 'dynamic_form'
gem "exception_notification", "~> 2.5.2"
108 changes: 108 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
GEM
remote: http://rubygems.org/
specs:
actionmailer (3.2.2)
actionpack (= 3.2.2)
mail (~> 2.4.0)
actionpack (3.2.2)
activemodel (= 3.2.2)
activesupport (= 3.2.2)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.1)
rack (~> 1.4.0)
rack-cache (~> 1.1)
rack-test (~> 0.6.1)
sprockets (~> 2.1.2)
activemodel (3.2.2)
activesupport (= 3.2.2)
builder (~> 3.0.0)
activerecord (3.2.2)
activemodel (= 3.2.2)
activesupport (= 3.2.2)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activeresource (3.2.2)
activemodel (= 3.2.2)
activesupport (= 3.2.2)
activesupport (3.2.2)
i18n (~> 0.6)
multi_json (~> 1.0)
arel (3.0.2)
builder (3.0.0)
dynamic_form (1.1.4)
erubis (2.7.0)
exception_notification (2.5.2)
actionmailer (>= 3.0.4)
foreigner (1.1.2)
activerecord (>= 3.0.0)
google4r-checkout (1.1.1)
money (>= 2.3.0)
hike (1.2.1)
i18n (0.6.0)
journey (1.0.3)
json (1.6.5)
mail (2.4.1)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.17.2)
money (4.0.2)
i18n (~> 0.4)
json
multi_json (1.1.0)
mysql2 (0.3.11)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.1)
rack (>= 0.4)
rack-ssl (1.3.2)
rack
rack-test (0.6.1)
rack (>= 1.0)
rails (3.2.2)
actionmailer (= 3.2.2)
actionpack (= 3.2.2)
activerecord (= 3.2.2)
activeresource (= 3.2.2)
activesupport (= 3.2.2)
bundler (~> 1.0)
railties (= 3.2.2)
railties (3.2.2)
actionpack (= 3.2.2)
activesupport (= 3.2.2)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.6)
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
sprockets (2.1.2)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.32)
uuidtools (2.1.2)
will_paginate (3.0.3)
xml-simple (1.1.1)

PLATFORMS
ruby

DEPENDENCIES
dynamic_form
exception_notification (~> 2.5.2)
foreigner
google4r-checkout (~> 1.1.0)
money (~> 4.0.1)
mysql2 (~> 0.3.0)
rails (= 3.2.2)
uuidtools
will_paginate
xml-simple (~> 1.1.1)
11 changes: 7 additions & 4 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Features:
Dependencies
------------

- Rails 2.1 or higher.
- Rails 3.0 or higher.
- PostgreSQL or MySQL


Expand All @@ -25,6 +25,9 @@ Installation
This is a brief outline of the steps required to get the development environment of Potion Store up
and running on your local machine.

- Install gems via Bundler
- Run ```bundle install```

- Edit the following config files to suit your needs

- config/store.yml
Expand All @@ -42,7 +45,7 @@ and running on your local machine.
- Edit config/database.yml
- run "rake db:migrate" to create the database schema

- Run script/server and test through
- Run ```rails s``` and test through
<http://localhost:3000/store> and
<http://localhost:3000/admin>

Expand All @@ -60,9 +63,9 @@ and running on your local machine.
Debugging
---------

1. gem install ruby-debug
1. ```gem install ruby-debug```
2. Put 'debugger' where you want to break in your source code
3. Start the app with 'script/server --debugger' to enable breakpoints
3. Start the app with ```rails s --debugger``` to enable breakpoints


Final Notes
Expand Down
7 changes: 2 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require(File.join(File.dirname(__FILE__), 'config', 'boot'))

require File.expand_path('../config/application', __FILE__)
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

require 'tasks/rails'
Potionstore::Application.load_tasks
2 changes: 1 addition & 1 deletion app/controllers/admin/charts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Admin::ChartsController < ApplicationController

before_filter :redirect_to_ssl, :check_authentication
#before_filter :redirect_to_ssl, :check_authentication

def revenue_history_days
limit = 30
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/admin/orders_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
class Admin::OrdersController < ApplicationController

layout "admin"

before_filter :redirect_to_ssl, :check_authentication

# GET /orders
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/products_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Admin::ProductsController < ApplicationController
layout "admin"

before_filter :redirect_to_ssl, :check_authentication
#before_filter :redirect_to_ssl, :check_authentication

# GET /products
# GET /products.xml
Expand Down
4 changes: 0 additions & 4 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
class AdminController < ApplicationController
# GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
verify :method => :post, :only => [ :destroy, :create, :update ],
:redirect_to => { :action => :list }

# Authentication stuff
before_filter :redirect_to_ssl
before_filter :check_authentication, :except => [:login]
Expand Down
9 changes: 3 additions & 6 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@

class ApplicationController < ActionController::Base

# Don't log any credit card data
filter_parameter_logging :password, :cc_number, :cc_code, :cc_month, :cc_year

def check_authentication
unless session[:logged_in]
session[:intended_url] = request.request_uri
session[:intended_url] = request.url
logger.debug('intended_url: ' + session[:intended_url])
redirect_to :controller => "/admin", :action => "login"
end
Expand All @@ -25,7 +22,7 @@ def redirect_to_ssl

# Convenience global function to check if we're running in production mode
def is_live?
return ENV['RAILS_ENV'] == 'production'
return Rails.env == 'production'
end


Expand Down Expand Up @@ -68,7 +65,7 @@ def effective_tax_tables_at(time)
end

def _initialize_google_checkout
environment = ENV['RAILS_ENV'] || 'production'
environment = Rails.env || 'production'

app_root = File.dirname(__FILE__) + '/../..'
config_dir = app_root + '/config'
Expand Down
9 changes: 2 additions & 7 deletions app/controllers/store/order_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

class Store::OrderController < ApplicationController
layout "store"

Expand All @@ -8,16 +7,12 @@ def index
new
render :action => 'new'
end

# GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
verify :method => :post, :only => [ :destroy, :create, :update ],
:redirect_to => { :action => :list }


def new
session[:order_id] = nil
@qty = {}
@payment_type = session[:payment_type]
@products = Product.find(:all, :conditions => {:active => 1})
@products = Product.where(:active => 1)
if params[:product]
@qty[params[:product]] = 1
elsif session[:items]
Expand Down
18 changes: 13 additions & 5 deletions app/models/order.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
require 'uid'
require 'uuidtools'
require 'ruby-paypal'

class Order < ActiveRecord::Base
has_many :line_items
belongs_to :coupon

before_create :generate_token

attr_accessor :cc_code, :cc_month, :cc_year
attr_accessor :skip_cc_validation
attr_accessor :email_receipt_when_finishing
Expand All @@ -26,8 +27,7 @@ def initialize(attributes = {}, form_items = [])
if form_items.length > 0
self.add_form_items(form_items)
end

self.unique_id = uid() if not self.unique_id

self.order_time = Time.now() if not self.order_time
end

Expand Down Expand Up @@ -363,7 +363,7 @@ def save
end

# Add UID if it hasn't been already
self.unique_id = uid() unless self.unique_id
self.uuid = generate_token() unless self.uuid

# Always update the total before saving. Always!!!
self.total = self.calculated_total
Expand Down Expand Up @@ -658,4 +658,12 @@ def gcheckout_refund_order
self.status = 'R'
self.save()
end

private
def generate_token
token = UUIDTools::UUID.timestamp_create.to_s
self.uuid = token
logger.debug("TOKEN : #{token}")
return token
end
end
24 changes: 12 additions & 12 deletions app/views/admin/_revenue_summary.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@
</tr>
<tr>
<th class="first">Orders</th>
<% for val in @num_orders -%>
<% for val in @num_orders %>
<td><%= val %></td>
<% end -%>
<% end %>
</tr>
<% for product in @products -%>
<% for product in @products %>
<tr>
<th class="first"><%= product %></th>
<% for i in 0..3 -%>
<% if @type == nil || @type == "quantity" -%>
<% for i in 0..3 %>
<% if @type == nil || @type == "quantity" %>
<td><%= @product_quantity[product][i] %></td>
<% elsif @type == "amount" -%>
<% elsif @type == "amount" %>
<td><%= number_to_currency(@product_revenue[product][i]) %></td>
<% elsif @type == "percentage" -%>
<% elsif @type == "percentage" %>
<td><%= number_to_percentage @product_percentage[product][i], :precision => 0 %></td>
<% end -%>
<% end -%>
<% end %>
<% end %>
</tr>
<% end -%>
<% end %>
<tr class="total">
<th class="first">Total</th>
<% for val in @revenue -%>
<% for val in @revenue %>
<td><%= number_to_currency(val) %></td>
<% end -%>
<% end %>
</tr>
<tr>
<th></th>
Expand Down
4 changes: 2 additions & 2 deletions app/views/admin/add_coupons.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<% @qty = {} %>
<% form_tag :action => "add_coupons" do -%>
<%= form_tag :action => "add_coupons" do %>
<p>Code: <%= text_field 'form', 'code' %></p>
<p>Amount: <%= text_field 'form', 'amount' %></p>
<p>Description: <%= text_field 'form', 'description' %></p>
<p>Coupons<%= text_area 'form', 'coupons' %></p>
<p><%= submit_tag 'Process Orders' %></p>
<% end -%>
<% end %>
12 changes: 6 additions & 6 deletions app/views/admin/generate_coupons.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1>Add Coupons</h1>

<% form_tag :action => "generate_coupons" do -%>
<%= form_tag :action => "generate_coupons" do %>

<table class="form">
<tr>
Expand Down Expand Up @@ -44,16 +44,16 @@
</tr>
</table>

<% end -%>
<% end %>

<% if @coupons -%>
<% if @coupons %>
<h2>Generated Coupons</h2>
<pre>
<% for coupon in @coupons -%>
<% for coupon in @coupons %>
<%= coupon.coupon %>
<% end -%>
<% end %>
</pre>
<% end -%>
<% end %>



Loading