Я делаю простую отправку писем с сообщением и темой, когда я хочу отправить почту на почту назначения, я получаю следующую ошибку: «Не удалось найти пользователя без идентификатора»
У меня есть следующий код:
app / mailers / notifier.rb:
def envio_mail(subject, message, user)
@user = User.find(user)
@muser = user
@body_message = message
mail(:to => @user.email, :subject => subject)
end
app / controllers / grattitude_controller.rb:
def create
@gratitude = Gratitude.new(params[:gratitude])
user = params[:user_id]
Notifier.envio_mail(params[:subject], params[:message], user).deliver
respond_to do |format|
if @gratitude.save
format.html { redirect_to(@gratitude, :notice => 'Gratitude was successfully created.') }
format.xml { render :xml => @gratitude, :status => :created, :location => @gratitude }
else
format.html { render :action => "new" }
format.xml { render :xml => @gratitude.errors, :status => :unprocessable_entity }
end
end
end
Это ошибка:
Started POST "/gratitudes" for 127.0.0.1 at 2020-02-26 17:10:55 -0500
Processing by GratitudesController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"iofCtlwd5CE5Zbuo5n6NzCo4Inksht4o05OiiwYUY24=", "gratitude"=>{"subject"=>"asdasd", "message"=>"<p>asda</p>", "user_id"=>"4"}, "commit"=>"Enviar mensaje"}
SCHEMA (0.6ms) SHOW TABLES
ClientParameterization Load (0.2ms) SELECT `client_parameterizations`.* FROM `client_parameterizations` LIMIT 1
User Load (0.2ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
Profile Load (0.2ms) SELECT `profiles`.* FROM `profiles` WHERE `profiles`.`id` = 1 LIMIT 1
Completed 404 Not Found in 130ms
ActiveRecord::RecordNotFound (Couldn't find User without an ID):
app/mailers/notifier.rb:405:in `envio_mail'
app/controllers/gratitudes_controller.rb:48:in `create'