如何在 controller.rb - rails 中添加按钮 link 4

How to add button link in controller.rb - rails 4

用户在我的站点注册后,需要激活他们的帐户。将向用户发送一封电子邮件。如果帐户未激活,用户将无法登录。

一条消息将显示:"Account is not activated. Check your email for an activation link."如何在警告消息中创建一个 link 或按钮,提示服务器向用户发送另一封激活电子邮件?

我尝试了 action_item<%=button_to

def create
  user = User.find_by(email: params[:session][:email].downcase)
  if user && user.authenticate(params[:session][:password])
    if user.activated?
      log_in user
      params[:session][:remember_me] == '1' ? remember(user) : forget(user)
      redirect_back_or user
    else
      message  = "Account not activated. "
      message += "Check your email for the activation link. "
      flash[:warning] = message 
      action_item :view, only: :show do 
      link_to 'Resend the activation link.', :action => "@user.send_password_reset_email", :controller => "PasswordResets"
    end
    redirect_to root_url
  end
end

我发现的一些错误:

您将在文件夹中放置一个 link_to 助手:app/views/* only

因此,如果您尝试将其放入 html.erb 文件中,您应该能够看到正在生成 link

 link_to 'Resend the activation link.', :action => "try_resend", :controller => "PasswordResets"

控制器:

class PasswordResets < ApplicationController
  def try_resend
    puts 'You should see this in console' 
  end
end