オブジェクト全体とその属性を変数に戻したいのですが、電子メールのみを返しているようです。params、railsとして電子メールを使用してfind_byからユーザオブジェクトを返す必要があります
がUserController
....
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を含むことができ、 ?
EDIT 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を追加するには、ファイル内の行9で
def account_activation(user)
@user = user
mail to: user.email, subject: "Account activation"
end
'routes.rb'を確認すると、' account_activations#edit'はおそらく存在しません。 –
経路が終了する最初のアカウントアクティベーションメールが送信されていますが、これは再送信です。だからあなたの言う 'find_by'は' find'メソッドのようにUserオブジェクトを返さなければなりません? find_byはコンソールで正常に動作します。 –
ルートとユーザーモデルには何が含まれていますか? –