Question

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
Was it helpful?

Solution

Ok so final answer I needed https instead of http and I needed to implement 2 ActiveResources like I specified in the question .

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top