Rails associations for current_user
I read this article some time ago: http://pivotallabs.com/users/nick/blog/articles/275-advanced-proxy-usage-part-i , which talks about AR proxies, etc.
The author pointed out what the problem is now.
This example will describe it.
class Gallery has_many :images, :class_name => 'Image' has_many :my_images, :class_name => 'Image' #, :conditions => "images.user_id == current_user.id" # FIX THIS end
class Image belongs_to :user belongs_to :gallery end
Note: I am using PostgreSQL
So when you access my all gallery images:
If I want to return all images:
So how do you pass the current user to the conditions in
User has_many :images has_many :galleries, through: :images
source to share
If I understand well, you want to end up with something like:
, has_many , , UserGallery.