Answer the question
In order to leave comments, you need to log in
How to properly send an email with dynamic data in rails?
There is a Post sign
Post.rb
has_many :responces
has_many :users, through: :responces
end
class Responce < ActiveRecord::Base
belongs_to :user
belongs_to :post
end
def create
@post = Post.find(params[:post_id])
@responce = @post.responces.build(responce_params)
@responce.user = current_user
if @responce.save
NotificationMailer.new_responce(@post.user).deliver
flash[:success] = "Привет"
redirect_to post_path @post
else
render 'new'
end
end
<%= @post.responce.price %> @post.responce.user.name
Answer the question
In order to leave comments, you need to log in
Responce is in what language? :)
In NotificationMailer :
def new_responce(responce)
@responce = responce
@responce_user = @responce.user
mail to: @responce.post.user.email #, subject: "Subject", ...
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question