我是Rails n00b,並且已被告知,爲了讓我跟蹤用戶帳戶的狀態(即付費,未付費(因此禁用),免費試用等),我應該使用'AASM'寶石。我如何在Rails 3中實現aasm以實現我想要的功能?
因此,我發現了一個似乎是最受歡迎的:https://github.com/rubyist/aasm但是說明非常模糊。
我有一個用戶模型和一個計劃模型。用戶的模型管理你可能期望的一切(用戶名,密碼,名字等)。計劃模型管理用戶應該分配給的訂閱計劃(帶有限制)。
所以我想弄清楚如何使用AASM創業板做我想做的事,但不知道從哪裏開始。
我是否創建新模型?那麼我是否需要在我的用戶模型和AASM模型之間建立關係?我如何建立關係?如在用戶'has_many'狀態?這對我來說似乎沒有多大意義。
任何指導將非常感激。
謝謝。
編輯:如果別人是像我這樣的AASMs混淆,這裏是它們的功能在Rails的一個很好的解釋以優良的鄉親羨慕實驗室:http://blog.envylabs.com/2009/08/the-rails-state-machine/
EDIT2:這個怎麼樣:
include AASM
aasm_column :current_state
aasm_state :paid
aasm_state :free_trial
aasm_state :disabled #this is for accounts that have exceed free trial and have not paid
#aasm_state :free_acct
aasm_event :pay do
transitions :to => :paid, :from => [:free_trial, :disabled]
transitions :to => :disabled, :from => [:free_trial, :paid]
end
envylabs鏈接不起作用了。以下是該博文的工作鏈接:http://madewithenvy.com/ecosystem/articles/2009/rails-state-machine/ – 2015-10-20 19:50:54