You’re not receiving notifications from this thread.
Was wondering id there is a way i can simply this ...
I was wondering if there is any way I can simplify this code, Ideally, I don't want to be looking up brands that are associated with the user, i want to do it on hit.
#Gets the ID associated to the current user brand_ids = current_user.brands.pluck(:id) #Looks up the articles associated with this user. @articles_count = Article.where(brand_id: brand_ids)
Thanks in advance
You can set up the association on the user to has_many through:
class User has_many :brands has_many :articles, through: :brands end
And then you can access them directly and it will be auto-scoped for you:
Cheers buddy. haha you know when you spend so long looking at the code you mind just goes blank :o lol
your telling me!
I been added likes to my app, now i am adding follows using a variant of the code you showed for the likes. And now for some reason i can't get the JS bit to work haha you have to refresh the page for the follow to register.
would this be the same if i wanted to get a variants volume type?
Would i need to add
, through: : products on the
has_one :volume_types in the
I have the following...
product has_many :product_variants, dependent: :destroy
product_variant belongs_to :product has_one :volume_types # table has: volume_type_id
Volume Type Model
volume_type belongs_to :product_variant #table: volume_types #t.string "short_name"