简体   繁体   中英

ActiveResource trying to access a 2 times nested url

This is the url I need to access

/api/v1/projects/{id}/tickets/{id}/time_entries

and this is my Project ActiveResource model so far ... I can get projects and tickets based on every project and I want to get every time_entrie based on tickets

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

Is this possible with only one ActiveResource model or do I need to make somekind of association between Project and another ActiveResource Ticket ?

//although I haven't seen anything about associations on the rails api documentation.

//Edit I've added a new TimeEntry ActiveResource model that looks something like this

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

Now if I run Project.get_time I get

ActiveResource::Redirection: Failed.  Response code = 302.  Response message = Found. => https://xyz.unfuddle.com/projects/38664/tickets/6336/time_entries

好的,所以最终答案是我需要https而不是http,并且需要实现2 ActiveResources,就像我在问题中指定的那样。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM