0
aasm
ブロック全体を文字列に入れてpayment_request
モデルに評価します。evalを使用してaasmブロックを実行するときのエラー
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"
除去する場合(:テスト)」、同じエラーここDEFであります次のポイント:
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'
評価?ありがとう。ここで