如何在Redmine中插入新关系

时间:2015-01-21 15:55:55

标签: ruby-on-rails ruby redmine redmine-api

我试图找到使用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中创建关系的正确语法是什么,因为我发现了它将链接的两个问题?

1 个答案:

答案 0 :(得分: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中,而不是为类更改它。