E
ErkA
hello I've strange problem with state machine
in my model
state_machine :user_state, :initial => :unconfirmed do
state :unconfirmed, :value => 0
state :confirmed, :value => 1
state :trusted, :value => 2
event :verify do
transition :unconfirmed => :confirmed
end
event :trust do
transition [ :unconfirmed, :confirmed] => :trusted
end
end
-----------
x ==> #<Price id: 88, user_id: 1, station_id: 13157,
session_id: "201924b30b53bd38250d396c252b2847", user_type: 2, price:
#<BigDecimal:9f0bdc0,'0.34E2',4(8)>, user_state: 0, created_at:
"2009-12-10 06:22:06", updated_at: "2009-12-10 07:46:33", ip:
"10.10.10.1">
-----------
x.user_state_transitions
==> [#<StateMachine::Transition attribute=:user_state
event=:verify from=0 from_name=:unconfirmed to=1 to_name=:confirmed>,
#<StateMachine::Transition attribute=:user_state event=:trust from=0
from_name=:unconfirmed to=2 to_name=:trusted>]
-----------
events.valid_for(x)
==> [#<StateMachine::Event name=:verify transitions=[:unconfirmed
=> :confirmed]>, #<StateMachine::Event name=:trust transitions=
[[:unconfirmed, :confirmed] => :trusted]>]
-------- and here we go:
x.verify!
StateMachine::InvalidTransition: Cannot transition user_state
via :verify from :unconfirmed
x.trust!
StateMachine::InvalidTransition: Cannot transition user_state
via :trust from :unconfirmed
on log Im getting only:
SQL (0.0ms) BEGIN
SQL (1.8ms) ROLLBACK
but if I use
x.verify false
==> true
what Im doing wrong or where is the problem?
best regards
ErkA
in my model
state_machine :user_state, :initial => :unconfirmed do
state :unconfirmed, :value => 0
state :confirmed, :value => 1
state :trusted, :value => 2
event :verify do
transition :unconfirmed => :confirmed
end
event :trust do
transition [ :unconfirmed, :confirmed] => :trusted
end
end
-----------
x ==> #<Price id: 88, user_id: 1, station_id: 13157,
session_id: "201924b30b53bd38250d396c252b2847", user_type: 2, price:
#<BigDecimal:9f0bdc0,'0.34E2',4(8)>, user_state: 0, created_at:
"2009-12-10 06:22:06", updated_at: "2009-12-10 07:46:33", ip:
"10.10.10.1">
-----------
x.user_state_transitions
==> [#<StateMachine::Transition attribute=:user_state
event=:verify from=0 from_name=:unconfirmed to=1 to_name=:confirmed>,
#<StateMachine::Transition attribute=:user_state event=:trust from=0
from_name=:unconfirmed to=2 to_name=:trusted>]
-----------
events.valid_for(x)
==> [#<StateMachine::Event name=:verify transitions=[:unconfirmed
=> :confirmed]>, #<StateMachine::Event name=:trust transitions=
[[:unconfirmed, :confirmed] => :trusted]>]
-------- and here we go:
x.verify!
StateMachine::InvalidTransition: Cannot transition user_state
via :verify from :unconfirmed
x.trust!
StateMachine::InvalidTransition: Cannot transition user_state
via :trust from :unconfirmed
on log Im getting only:
SQL (0.0ms) BEGIN
SQL (1.8ms) ROLLBACK
but if I use
x.verify false
==> true
what Im doing wrong or where is the problem?
best regards
ErkA