我的模型包含一个名为“status”的字段。我已将其更改为DB中的字符串类型。我还在AASM中使用枚举。
这是我的代码:
private double? GetNumber()
{
double? result = null;
try {
result = Convert.ToDouble (Console.ReadLine ());
} catch (System.FormatException) {
Console.Beep ();
Console.WriteLine ("");
Console.WriteLine ("You have entered an invalid number!");
Console.WriteLine ("");
}
return result;
}
...
// prompt for first number
double? num1 = null;
while (!num1.HasValue)
{
Console.Write ("What is the first number? ");
num1 = GetNumber();
}
// prompt for second number
double? num2 = null;
while (!num2.HasValue)
{
Console.Write ("What is the second number? ");
num2 = GetNumber();
}
// calculate result
answer = num1.Value + num2.Value;
我这样申请:
class Card < ActiveRecord::Base
include AASM
enum status: {
default: 0,
published: 1,
deleted: 2
}
aasm column: :status, enum: true, skip_validation_on_save: true, no_direct_assignment: true do
state :default, initial: true
state :published
state :deleted
event :publish do
transitions from: :default, to: :published
end
event :delete do
transitions from: :published, to: :deleted
end
end
end
无论我拨打Card card = Card.first
card.publish
还是card.publish
,我都会收到如下错误:
card.delete
这让我困惑了几天。任何帮助都会受到赞赏。
答案 0 :(得分:0)