在買家購買了演出之後,我的應用程序中買家和賣家都會收到一封電子郵件,通知他們收件箱。 這是user_mailer.rb
型號:我發送給買家如何在Rails中顯示買家名稱4-Action Mailer Views
class UserMailer < ActionMailer::Base
default from: "[email protected]"
def buyer(gig,email)
@gig = gig
@email = email
mail(to: @email, subject: 'box delivery')
end
def seller(gig,email)
@gig = gig
@email = email
mail(to: @email, subject: 'new box order')
end
end
現在我可以做的意見,在郵件模板。
1.@gig.user.name
=它會顯示賣家名稱,誰擁有演出。如何顯示誰買了演出買家名稱:演出
問題的
2.
@gig.title and @gig.description
=說明和標題?我想這樣說:「親愛的buyer.name,賣方@ gig.user.name(這一個工程) 交付訂單。
千兆模式
has_many :purchases
has_many :buyers, through: :purchases
has_many :sellers, through: :purchases
belongs_to :user
用戶模型
has_many :purchases, foreign_key: 'buyer_id'
has_many :gigs, through: :purchases, source: :buyer
has_many :gigs, dependent: :destroy
has_many :sales, foreign_key: 'seller_id', class_name: 'Purchase'
採購模式
class Purchase < ActiveRecord::Base
belongs_to :gig
belongs_to :buyer, class_name: 'User'
belongs_to :seller, class_name: 'User'
end
千兆控制器
class GigsController < ApplicationController
def downloadpage
ActiveRecord::Base.transaction do
if current_user.points >= @gig.pointsneeded
@purchase = current_user.purchases.create(gig: @gig, seller: @gig.user)
if @purchase
current_user.points -= @gig.pointsneeded
@gig.user.points += @gig.pointsneeded
current_user.save
if @gig.user.save
UserMailer.buyer(@gig,current_user).deliver
UserMailer.seller(@gig,@gig.user.email, current_user.name).deliver
render 'successful_download', locals:{link:@gig.boxlink}
end
end
else
redirect_to :back, notice: "You don't have enough points,upload a box and start getting them."
end
end
end
end
假設你有一個適當的登錄系統就不會買家是CURRENT_USER? – ChrisBarthol
是的,我確實嘗試了current_user.name,但發送到收件箱時發生錯誤,因爲current_user不適用於郵件模型 –
請添加您的控制器代碼。 –