【问题标题】:How do You Insert New Relations in Redmine如何在 Redmine 中插入新关系
【发布时间】:2015-01-21 15:55:55
【问题描述】:

我正在尝试找到使用 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 中创建关系的正确语法是什么?

【问题讨论】:

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


    【解决方案1】:

    我已经找到了解决办法。

    您需要使用 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 中,而不是为类更改它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-26
      相关资源
      最近更新 更多