0
這是我需要訪問的ActiveResource試圖訪問2次嵌套鏈接
/api/v1/projects/{id}/tickets/{id}/time_entries
的URL,這是我的項目的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模型或做我需要做somekind的項目和其他的ActiveResource票之間的關聯?
//雖然我還沒有看到有關rails api文檔中關聯的任何信息。
//編輯 我補充說,看起來像這樣
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
如果您嘗試'self.site =「https://xyz.unfuddle.com/api/v1/projects/#{params[:project]}/tickets/#{params[:ticket]}/ 「'? –
這就是我正在做的事情。 – lesce
抱歉沒有看到's':P ..它似乎解決了我的問題 – lesce