我想將整個對象及其屬性返回給我的變量,但它似乎只返回電子郵件。在意見需要從find_by返回用戶對象作爲params,rails使用電子郵件
Userscontroller
....
def resend_act_create
@user = User.find_by(email: params[:user][:email])
if @user
@user.send_activation_email
flash[:info] = "Please check your email to activate your account."
redirect_to root_url
else
flash[:warning] = "Could not find email in database"
render 'account_activations/new'
end
end
...
服務器錯誤/ usermailer/account_activations.html.erb
ActionView::Template::Error (No route matches {:action=>"edit", :controller=>"account_activations", :email=>"[email protected]", :id=>nil} missing required keys: [:id]):
6: Welcome to the Sample App! Click on the link below to activate your account:
7: </p>
8:
9: <%= link_to "Activate", edit_account_activation_url(@user.activation_token,
10: email: @user.email) %>
我不知道如何建立我的控制器動作,所以我可以包括路由的ID ?
編輯添加User.rb和路線
class User < ApplicationRecord
....
def send_activation_email
UserMailer.account_activation(self).deliver_now
end
....
的routes.rb
....
resources :account_activations, only: [:edit]
UserMailer.rb
def account_activation(user)
@user = user
mail to: user.email, subject: "Account activation"
end
檢查你的'routes.rb','account_activations#edit'可能不存在。 –
路線退出我有第一個帳戶激活電子郵件通過它這是一個重發。所以你說'find_by'應該像'find'方法那樣返回用戶對象? find_by在控制檯中正常工作。 –
你的路線和用戶模型包含什麼? –