Active Resource basics

Assuming I have models that look like these:

class Job < ActiveRecord::Base
has_many :locations
end

class Location < ActiveRecord::Base
belongs_to :job
end

I have routes that look like this:

map.resources :job do |job|
job.resources :location
end

I’m exposing these model using ActiveResource like this:

class Job < MyLocalResource
end

class Location < MyLocalResource
site += ‘/job/:job_id’
end

How would I run a method on job, (like submitting the job to queue of
some sort) after I create location? Am I approaching this from the
wrong direction? Should I create an observer on the job model?

On 12/31/06, bryanl [email protected] wrote:

site += ‘/job/:job_id’
end

How would I run a method on job, (like submitting the job to queue of
some sort) after I create location? Am I approaching this from the
wrong direction? Should I create an observer on the job model?

Active Resource doesn’t reflect the associations in your models, but you
can, for example:

Location

def job
@job ||= Job.find(job_id)
end

Job

def enqueue
connection.post(“#{element_path(id)};enqueue”)
end

Then location.job.enqueue! to submit the location’s job to a queue.

jeremy