当我新建LDAP认证模式时,遇到如下错误:

timeout是auth_source的一个属性,但是却没有生成timeout的读方法,经过跟踪发现是因为添加了 safe_attributes 中的 bad_attribute_names 方法返回的数组包含了timeout关键字,导致该方法没有生成。

解决方法:从Gemfile中去掉safe_attributes,然后 bundle install 解决。

关键句子:ActionView::Template::Error (private method `timeout' called for #<AuthSourceLdap:0x007fcfc0fb8d70>

 

删除了上面的safe_attributes后,redmine新建问题又有一个错误:

这是由于issue_relations表的有一个列名叫做delay,而刚好AR中定义了这个方法,因此在生成实例方法时抛出了这个异常。解决办法就是不自动生成delay的实例方法,如下:

def _delay
  read_attribute(:delay)
end
def _delay=(value)
  write_attribute(:delay, value)
end
# 因为delay也是AR的一个方法,所以会导致报错,这个方法可以保证不生成delay的实例方法,完全由类自己实现
def self.instance_method_already_implemented?(method_name)
  return true if method_name == "delay"
  super
end

关键句子:ActiveRecord::DangerousAttributeError (delay is defined by Active Record. Check to make sure that you don't have an attribute or method with the same name.)

 

posted on 2016-04-06 10:22  oslivan  阅读(473)  评论(0编辑  收藏  举报