当前位置: 动力学知识库 > 问答 > 编程问答 >

ruby on rails 3 - Issues with validates_uniqueness_of and state_machine transition

问题描述:

I have a problem with the rails 'validates_uniqueness_of' function and the state_machine gem. Please look at the code below:

state_machine :initial => :foo do

state :bar do

validates_uniqueness_of :something

end

event :action do

transition :foo => :bar

end

end

As you can see, I want to validate the uniqueness of 'something' when the model is in the state of 'bar'. However, the validations seems to take already place during the transition. Therefor, my instance becomes invalid and the transition never finishes.

So, is there a way to make sure the validation takes place AFTER the transition had happened? Thank you.

网友答案:

Sorry for who is having a similar problem, but we solved the issue otherwise, by making the customer change their use case ;-) .

分享给朋友:
您可能感兴趣的文章:
随机阅读: