这是我需要访问的网址
/api/v1/projects/{id}/tickets/{id}/time_entries
到目前为止,这是我的 Project ActiveResource 模型......我可以根据每个项目获取项目和票证,并且我想根据票证获取每个 time_entrie
class Project < ActiveResource::Base
self.site = "https://xyz.unfuddle.com/api/v1"
def self.get_time
Project.all.each do |project|
project.get(:tickets).each do |ticket|
#from here I want to get to time_entrie
#after the last_edit
TimeEntry.addparams({project: project.id,ticket: ticket["id"]})
end
end
end
这是否可能仅使用一个 ActiveResource 模型,还是我需要在 Project 和另一个 ActiveResource Ticket 之间建立某种关联?
//虽然我在rails api文档上没有看到任何关于关联的信息。
//编辑我添加了一个新的 TimeEntry ActiveResource 模型,看起来像这样
class TimeEntry < ActiveResource::Base
self.collection_name="time_entries"
def self.addparams(params)
self.site = "http://xyz.unfuddle.com/api/v1/projects/#{params[:project]}/tickets/#{params[:ticket]}/"
self.all
end
现在,如果我运行 Project.get_time 我得到
ActiveResource::Redirection: Failed. Response code = 302. Response message = Found. => https://xyz.unfuddle.com/projects/38664/tickets/6336/time_entries