Association extensions: how to access the object?

With association extensions, like user.items.tagged(“foo”), how do I
access the “user” object from within the extension method? The code
would be e.g.

class User < ActiveRecord::Base
has_and_belongs_to_many :items do
def tagged(tag)
return “These are items tagged %s from user %s.” % [tag, ???]

but how would I get a hold of the user in question, within that method?

Since “self” in the method refers to the “items” collection, I can do
self[0].user, but that seems very much like a hack, and will obviously
not work if the items collection is empty.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs