2013-04-25 63 views
0

我有一个带有名为Events的表的Rails应用程序。当事件被创建时,名为maxsynch的字段被设置为“n”。我们使用Mule将这些事件拖入另一个应用程序。当它拉出其中一个事件时,它将maxsynch设置为“s”。Rails根据记录中的列值将记录设置为只读

我想知道是否可以将maxsynch =“s”的记录设置为只读。

我发现StackOverflow上下面的代码:

def create_or_update 
    raise ReadOnlyRecord if readonly? 
    result = new_record? ? create : update 
    result != false 
end 

def readonly? 
    new_record? ? false : true 
end 

这应该是一个记录集为只读它被创建后(我认为)。我想通过首先尝试开始测试。然后更改代码以定义只读?作为maxsynch =“s”。

当我把代码放到我的事件控制器并尝试更新的事件,我得到以下错误:

uninitialized constant Event::ReadOnlyRecord 

从代码行:

 raise ReadOnlyRecord if readonly? 
+0

您可能想要在验证中做到这一点 – cpuguy83 2013-04-25 23:35:06

回答