github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

caelum / restfulie-test

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 7
    • 2
  • Source
  • Commits
  • Network (2)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.
  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

using render_resource 
guilherme silveira (author)
Wed Jan 27 20:10:08 -0800 2010
commit  86ab8a539c4723f88fe31d23ea891290eb1e43c1
tree    d0e1cf6d364baf0967e0aff624cd4a20f91e37e2
parent  a7e477894e1d2aafd0d5689cd50faa0740c52331
restfulie-test / app / models / order.rb app/models/order.rb
100644 64 lines (53 sloc) 1.819 kb
edit raw blame history
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
class Order < ActiveRecord::Base
  
  acts_as_restfulie do |order, transitions|
    transitions << :execute_it if (order.status == "preparing") && order.paid_one_minute_ago?
    transitions << [:thanks, { :action => :thanks }] if order.status == "received"
  end
  
  has_and_belongs_to_many :trainings
  has_many :payments
 
  state :unpaid, :allow => [:latest, :pay, :cancel]
state :cancelled, :allow => :latest
state :received, :allow => [:latest, :check_payment_info]
state :preparing, :allow => [:latest, :check_payment_info]
state :ready, :allow => [:latest, :receive, :check_payment_info]# do |order|
# order.paid_one_minute_ago?
# end
 
transition :check_payment_info do |order|
{:controller => :payments, :action => :show, :order_id => order.id, :payment_id => order.payments[0].id, :rel => "check_payment_info"}
end
transition :latest, {:action => :show}, {:not_found => 404, :no_change => 304}
  transition :cancel, {:action => :destroy}, :cancelled
# 405 ==> (dont do it)
# 409 ==> (try again)
# order.status=="cancelled".... trying to cancel ==> 405
# order.status=="preparing".... trying to update it ==> 409
# order.status=="unpaid".... invalid data supplied ==> 400?
  transition :pay, {}, :preparing
transition :receive, {}, :received
transition :execute_it, {}, :ready
 
  def paid_one_minute_ago?
    # takes one minute to be prepared
    self.paid_at < (Time.now - 1.minute)
  end
 
   def pay(payment)
     debugger
     move_to :pay
     self.paid_at = Time.now
     @payment = payment
     @payment.order = self
   end
  
  def total_price
    total = 0
    @trainings.each do |x|
      total += x.price
    end
    total
  end
  
  def paid?
    payments.size > 0
  end
 
    # def can_cancel?
    # raise 405 if @status == :cancelled
    # # ...
    # end
  
end
 
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server