1

我正在尝试找到使用 Ruby 在 Redmine 中的问题之间插入新关系的语法。

我一直在尝试的代码:

require 'rubygems'
require 'active_resource'
class Issue < ActiveResource::Base
     self.site = '[the site]'
     self.user = '[the user]'
     self.password = '[the password]' #not hard coded
     self.format = :json #I've had issues with Issue.find(i) without explicitly stating the format
end

class IssueRelation < ActiveResource::Base
     self.site = '[the site]'
     self.user = '[the user]'
     self.password = '[the password]' #not hard coded
     self.format = :json #I've had issues with Issue.find(i) without explicitly stating the format
end

issue1 = Issue.find(1)
issue2 = Issue.find(2)

puts issue1.id
puts issue2.id

relation = IssueRelation.new(
    :issue => issue1,
    :issue_to => issue2,
    :relation_type => 'relates'
    )

if relation.save
    puts relation.id
else
    puts relation.errors.full_message
end

我得到的输出:

1
2
...'handle_response': Failed. Response code = 404. Response Message = not found.

输出表明已成功找到问题 1 和 2,但我用于关系的名称无效,因此未找到 404。

鉴于我发现了它会链接的两个问题,在 Redmine 的 API 中创建关系的正确语法是什么?

4

1 回答 1

0

我已经找到了解决方案。

您需要使用 Relation 对象,而不是使用 IssueRelation 对象。

此外,在使用 Relation 对象之前,您必须更改站点。

Relation.site="[the site]/issues/#{issue1.id}/"
rel = Relation.new(
       :issue_to_id => issue2.id,
       :relation_type => 'relates'
      )
rel.save

您可以将 :site 放在 Relation.new 中,而不是为班级更改它。

于 2015-06-10T10:42:10.760 回答