我们将整个aasm
块放在字符串中并将其评估为payment_request
模型。这是def:
class PaymentRequest < :ActiveRecord::Base
include AASM
def self.load_wf_spec(wf_spec, wf_def_name)
eval("aasm(:#{wf_def_name}) :column => 'wf_state' {#{wf_spec}}")
end
end
错误是:
Failure/Error: eval("aasm(:#{wf_def_name}) :column => 'wf_state' {#{wf_spec}}")
SyntaxError:
(eval):1: syntax error, unexpected ':', expecting end-of-input
aasm(:test) :column => 'wf_state' {state :...
^
# ./app/models/payment_requestx/payment_request.rb:11:in `eval'
以下是变量的值:
wf_def_name = 'test'
wf_spec = "state :initial_state, :initial => true
state :ceo_reviewing
state :approved
state :stamped
state :paid
state :rejected
event :submit_test do
transitions :from => :initial_state, :to => :ceo_reviewing
end
event :ceo_approve_test do
transitions :from => :ceo_reviewing, :to => :approved
end
event :ceo_reject_test do
transitions :from => :ceo_reviewing, :to => :rejected
end
event :ceo_rewind_test do
transitions :from => :ceo_reviewing, :to => :initial_state
end
event :stamp_test do
transitions :from => :approved, :to => :stamped
end
event :pay_test do
transitions :from => :stamped, :to => :paid
end"
如果删除(:test)&#39;,则相同的错误指向下一个:
Failure/Error: eval("aasm :column => 'wf_state' {#{wf_spec}}")
SyntaxError:
(eval):1: syntax error, unexpected '{', expecting end-of-input
aasm :column => 'wf_state' {state :initial_state, :initial => true
^
# ./app/models/payment_requestx/payment_request.rb:11:in `eval'
评估中缺少什么?
答案 0 :(得分:0)
以下是它的作用:
eval("aasm(:#{wf_def_name}, :column => 'wf_state') {#{def_string}}")