実現したいこと
RedmineAPIへActiveResourceを使用して新しくチケット登録をしたい。
現状
以下のURLでは、Redmineを、「http://www.example.com/redmine/」に設置したものとしています。
ActiveResourceを使用して以下のソースでRedmineAPIからチケットの情報取得はできました。
Model
ruby:support_ticket
1require 'active_resource' 2 3class SupportTicket < ActiveResource::Base 4 5 def self.configure 6 self.site = 'http://www.example.com/' 7 self.headers['X-Redmine-API-Key'] = 'API KEY' 8 end 9 10 def self.find_ticket(no) 11 self.find(:one, from: "/redmine/issues/#{no}.json", params: { include: 'journals' }) 12 end 13 14end
controller
ruby:contact_controller.rb
1class ContactController < ApplicationController 2 3 before_action :resources_initialize 4 5 def index 6 @data = get_ticket(1) 7 end 8 9 private 10 11 # ActiveResource初期化(header消失防止) 12 def resources_initialize 13 SupportTicket.configure 14 end 15 16 # 指定されたIDのチケット情報の取得 17 def get_ticket(no) 18 ticket = SupportTicket.find_ticket(no).to_json 19 JSON.parse(ticket) 20 end 21 22end
おわかりの方、ご指導よろしくお願い申し上げます。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。