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.

出力は、Issue 1 と 2 が正常に見つかったことを示していますが、関係に使用している名前が無効であるため、404 が見つかりませんでした。

リンクする 2 つの問題が見つかった場合、Redmine の API でリレーションを作成するための正しい構文は何ですか?

4

1 に答える 1

0

私はこれに対する解決策を発見しました。

IssueRelation オブジェクトを使用する代わりに、Relation オブジェクトを使用する必要があります。

また、Relation オブジェクトを使用する前に、サイトを変更する必要があります。

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

クラス用に変更する代わりに、Relation.new に :site を入れることもできます。

于 2015-06-10T10:42:10.760 に答える