在Spree的源码中,有一个next
的order方法
def update
if @order.update_attributes(object_params)
persist_user_address
unless @order.next
flash[:error] = @order.errors.full_messages.join("\n")
redirect_to checkout_state_path(@order.state) and return
end
# ...
end
但我不知道它在哪里,我无法在 Order
模型、Checkout
模块 ( https://github.com/spree/spree/blob/master/core/app/models/spree/order/checkout.rb ) 和 state_machine gem 中找到它。
最佳答案
它是通过一些技巧在 state_machine 中定义的。具体在这里:
很难找到,因为 Ruby 中提供了元编程,它在 Spree 中使用得相当多,并且在 state_machine gem 中广泛使用。
谢天谢地,Pry是查找事物定义位置的好工具。
~/d/s/sandbox (2-0-stable|✔) ❯❯❯ pry -r ./config/environment
[1] pry(main)> show-source Spree::Order.first.next
From: /home/gmacdougall/.rvm/gems/ruby-1.9.3-p392/gems/state_machine-1.2.0/lib/state_machine/machine.rb @ line 764:
Owner: Spree::Order :state instance helpers
Visibility: public
Number of lines: 3
define_method(method) do |*block_args|
block.call((scope == :instance ? self.class : self).state_machine(name), self, *block_args)
end
关于ruby-on-rails - spree 订单的 state_machine 中的 "next"在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20485114/