Ruby on Rails Sunday, June 26, 2011

paulo <paul.a.taylor84@...> writes:

>
> Hi guys,
>
> I'm having an issue establishing a has_many and/or belongs_to
> relationship between two of my models.
> One of them is 'local' if you like (called site), i.e. standard model
> in local db, the other is a RESTful resource (called audit), defined
> using the self.site method. I have checked and the audit class URL is
> providing a 'site_id' field as expected.
>
> When adding a 'belongs_to :site' reference to audit, I get the
> following error:
>
> 'app/app/models/audit.rb:3: undefined method `belongs_to' for
> Audit:Class (NoMethodError)'
>
> Are relationships like this not possible?
>
> Thanks again chaps,
>
> Paul
>


Looks like you're using a staright Class or ActiveRecord rather than
ActiveResource. Make sure your audit class looks something like:

class Audit < ActiveResource::Base
self.site = "http://www.myawesomesite.com/"
end


--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment