0
我试图访问以下邮件中的卖家名称(seller.name)。 Resa是卖家的子女(卖家has_many resas和Resa属于卖家)。从Rails 4中的Mailer访问属性
在 应用程序/邮寄者/ resa_mailer.rb
class ResaMailer < ActionMailer::Base
default from: '[email protected]'
def request_mail(resa)
@email = resa.request_email
@maturity_date = resa.maturity_date
@amount = resa.amount
@currency = resa.currency
@request_expiry_date = resa.request_expiry_date
@description = resa.description
@seller = Seller.where(["seller_id = resa.seller_id"])
mail to: @email, subject: @seller.name+' requests a deposit'
end
end
这被称为在resas_controller#创建:
class ResasController < ApplicationController
before_action :set_resa, only: [:show, :edit, :update, :destroy]
before_action :authenticate_seller!
def new
@resa = current_seller.resas.new
end
def create
@resa = current_seller.resas.new(resa_params)
@resa.seller_id = current_seller.mp_id
respond_to do |format|
if @resa.save
ResaMailer.request_mail(@resa).deliver
format.html { redirect_to @resa, notice: 'Resa was successfully created.' }
format.json { render action: 'show', status: :created, location: @resa }
else
format.html { render action: 'new' }
format.json { render json: @resa.errors, status: :unprocessable_entity }
end
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_resa
@resa = Resa.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def resa_params
params.require(:resa).permit(:resa_date, :maturity_date, :amount, :currency, :request_expiry_date, :request_status, :maturity_status, :description, :seller_id, :buyer_id, :request_email)
end
端
感谢您的回复。我删除了3个投入并且错误消失了,但是没有名称(即“Bill”),我得到了“卖方”。 任何想法? – Dwidoo
没有足够的声望尚未被允许upvote – Dwidoo