restful_authentication with state machine

一直使用 restful_authentication 作用户认证,最近它加上的状态机功能(用了 acts_as_state_machine),装上以后遇到灵异事件,系统发出的激活邮件里面的激活码和数据库里面存的不一样。我并不了解 acts_as_state_machine 的具体机制,只是觉得下面一行可能运行了两遍:

state :pending, :enter => :make_activation_code

Google 了一下,在作者的 README 里找到答案:

Pay attention, may be this is not an issue for everybody, but if you should have problems, that the sent activation_code does match with that in the database stored, reload your user object before sending its data through email something like:

 

 

class UserObserver < ActiveRecord::Observer
      def after_create(user)
        user.reload
        UserMailer.deliver_signup_notification(user)
      end
      def after_save(user)
        user.reload
        UserMailer.deliver_activation(user) if user.recently_activated?
      end
end

Tags: ,

One Response to “restful_authentication with state machine”

  1. blogring.org Says:

    Blogring for restful_authentication…

    Blogring for restful_authentication…

Leave a Reply