我有一个几年前有人写的 ruby/rails/hobo 系统,我需要移植到最新版本的 ruby/rails/hobo。似乎 ruby 并不关心向后兼容性,所以以前在旧应用程序中工作的代码不再工作了:
在 observation.rb 模型文件中,旧应用程序有这个:
belongs_to :survey
has_one :site, :through => :survey
def create_permitted?
acting_user == self.survey.contact or acting_user.administrator?
end
survey.rb 模型文件有这个:
belongs_to :contact, :class_name => 'User', :creator => true
不幸的是,observation.rb 中的代码在新的 ruby/rails/hobo 下不起作用,它给了我错误:
NoMethodError in Observations#index
Showing controller: observations; dryml-tag: index-page where line #1 raised:
undefined method `contact' for nil:NilClass
Extracted source (around line #1):
0
Rails.root: /home/simon/ruby/frogwatch2
Application Trace | Framework Trace | Full Trace
app/models/observation.rb:48:in `create_permitted?'
应该如何更改“create_permitted”方法?我发现 ruby/rails/hobo 的文档非常糟糕(这很公平,因为它是免费软件)。另外我什至不知道如何开始在谷歌上搜索这个(我已经尝试了好几天)。
请帮忙!:)