kcurtin
kcurtin

Reputation: 521

Displaying Action Mailer variable in view returns "nil"

I am trying to let a user submit a form that sends an email message to another user. Everything is working fine, except I am trying to store the body of the email in a variable to display in the view for the mailer and am getting 'nil'. I set up a user_mailer.rb:

class UserMailer < ActionMailer::Base
  default :from => "[email protected]"

  def message_user(user, recipient, subject, body)
@user = user
@recipient = recipient
@body = "#{body}"
mail(:to => "#{recipient.name} <#{recipient.email}>", :subject => "Reelify message: #{subject}" )
  end
  end

and here is my messages_controller.rb :

def new
@user = current_user

if !params[:receiver].blank? and !params[:subject].blank? and !params[:body].blank?
  @recipient = User.find_by_name(params[:receiver])
  UserMailer.message_user(@user, @recipient, params[:subject], params[:body]).deliver
  flash[:notice] = "This flash means it should work.. #{@user.name} #{@recipient.name}"
end

end

When I call @body in the view, it is blank (@body.inspect) results in 'nil'. However, if I do something like: #{body} in place of the subject line, the text will render fine.

Anyone have any clue whats going on?

Upvotes: 1

Views: 534

Answers (1)

gayavat
gayavat

Reputation: 19398

how about @ user, is it displayed correctly? May be @body is used by rails, try rename.

Upvotes: 1

Related Questions