Santosh Aryal Santosh Aryal - 1 year ago 77
Ruby Question

Rails mailer view template pass value send by a form

Its my first attempt to use the rails mailer to send email. I however is able to send plain emails but when I tried to pass the logged in user (current_user) name and params values send by the form I am getting the error. Undefined method 'params'.


class PaymentMailer < ApplicationMailer
def success(user)
mail(to: "#{user.first_name} #{user.last_name} <#{}>", subject: "Payment Successful")


<div class = "col-sm-12">
<h1>Payment Successful</h1>
<p>Dear <%= user.first_name %>, Thank you for being a part of our system<br>
Your invoice (#<%= params[:id] %>) has been generated.
<div class = "clearfix"></div>
<div class = "col-sm-6">
<table class = "table">
<th>Paid Ammount</th>
<th>Card Transaction Fee (2.9% + 0.30)</th>
<th>Credited Ammount</th>
<td>&euro;<%= params[:amount] %></td>
<h3>Total credited amount in your Account is: </h3>
<div class = "clearfix"></div>


amount = params[:amount]
@user = current_user
netamt = (amount.to_f - ((amount.to_f*2.9)/100 + 0.30))
payment = @user.payments.create(:amount => netamt, :method => "Card", :txn_code => params[:stripeToken])
@user.update_attribute(:balance, @user.balance+netamt)

Please guide me.

Answer Source

Just change in your payment controller after the payment, do like that


And in your mailer do

class PaymentMailer < ApplicationMailer
  def success(payment)
    @payment = payment
    @user = payment.user
    mail(to: "#{@user.first_name} #{@user.last_name} <#{}>", subject: "Payment Successful")

and in your mailer template use #for payment id

@payment.amount #for amount

@user.first_name #for user name
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download