2017-03-05 6 views
0

注文確認で、売り手とユーザーの両方が確認を受け取りますが、追加した後に、seller_idまたはbuyer_idのレールがエラーを吐き出します!Railsどのようにメーラーにforeign_keyを取得しますか?

私は解決策として、どこsuerに探していますが、

誰かがメーラーにFOREIGN_KEYを渡す方法のアイデアを持っている固有のIDを見つけられませんでしたか?

感謝の

class Order < ActiveRecord::Base 


    belongs_to :seller, foreign_key: 'seller_id', class_name: 'Shop' 
    belongs_to :buyer, foreign_key: 'buyer_id', class_name: 'User' 

end 





def order_confirmation(order) 

    @order = order 
    @buyer = Order.where('buyer_id') 
    mail(to: @buyer.email, subject: 'confirmation', &:html) 
    end 

def order_confirmation_seller(order) 
    @order = order 
    @seller = Order.where('seller_id') 
    mail(to: @seller.email, subject: 'confirmation', &:html) 
    end 

答えて

0

Order.where('buyer_id')は有効なものではないようです。 Order.where(buyer: order.buyer)を使用して、買い手が購入したすべての注文を取り出すことができます。しかし、与えられた場合には、メソッドの引数としての順序があります。

私が使用することをお勧めします:

  • @buyer = order.buyer
  • @seller = order.seller

とチップ:order_confirmation_for_sellerorder_confirmation_for_buyerは良く命名である可能性があります。

関連する問題