I have the following code in my controller:
@variants_hash = LineItem.find(:all, :joins => :drop_ship_orders, :conditions => {:drop_ship_order_line_items =>{:drop_ship_order_id => params[:drop_ship_order_ids]}, :drop_ship_orders => {:completed_at.not_eq => nil, :retailer_id => current_user.retailer.id}}).group_by{ |li| li.variant }
@variants = @variants_hash.keys
And obviously it’s not pretty, I was thinking of implementing it as a standalone method in my ActiveRecord.
I’ll call the following instead: LineItem.find_variants(params, retailer_id)
How can I implement that standalone method and if there is a much easier and cleaner alternative.
Answer: