On 12/31/06, bryanl <bryanliles-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> 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?
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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---