New to Ruby, Rails, and OOP in general. I've been through the "Ruby on Rails Tutorial: Learn Web Development with Rails" and about 80% through "Agile Web Development with Rails 4" but I can't visually figure this out. I was hoping someone can help me understand, maybe I'm wording it wrong.
Models: User, Team, Membership, Order, OrderLine
It's a pretty basic setup. (short hand, if you will...) Team belongs_to :user (owner, not terribly relevant here) Users has_many :teams through: :memberships Team has_many :users through: :memberships OrderLine belongs_to :team Note an OrderLine is assigned to a team, not a whole Order.
I'm trying to display all OrderLines which are associated with the currently logged in user (current_user). While this doesn't actually work, I feel it's close to producing. It also feels super dirty.
def index
@memberships = current_user.memberships.ids
membership_list = @memberships.join(", ")
@OrderLines = OrderLine.where("team_id IN (?)", membership_list)
end
Cheers!
Some times all you need is a break.