Ruby on rails 在路径中签名后

Ruby on rails 在路径中签名后,ruby-on-rails,devise,Ruby On Rails,Devise,我在应用程序中使用design 我想在用户登录时弹出一条欢迎消息 因此,在我的应用程序\u controller.erb中,我定义了: class ApplicationController < ActionController::Base protect_from_forgery before_filter :authenticate_user! def after_sign_in_path_for(user) alert('Welcome!') end

我在应用程序中使用
design

我想在用户登录时弹出一条欢迎消息

因此,在我的
应用程序\u controller.erb
中,我定义了:

class ApplicationController < ActionController::Base
  protect_from_forgery
  before_filter :authenticate_user!

  def after_sign_in_path_for(user)
    alert('Welcome!')
  end

  def after_sign_out_path_for(user)
    new_user_session_path
  end
end

默认情况下,designe添加flash消息。无需设置flash消息。只需在视图中显示flash消息。请尝试下面的代码

在应用程序中/views/layouts/application.html.erb

<% flash.each do |type, message| %>
  <div class="flash">
     <%= message %>
  </div>        
<% end %> 
最后更改方法的路径中的后符号

def after_sign_in_path_for(user)
  users_dashboard_path
end

您正在从rb文件调用javascript函数“alert()”。您应该在中定义路径

  def after_sign_in_path_for(user)
    some_path
  end

在带有javascript_标记的视图中使用alert(),这是我发现的在安装了引导程序的情况下发送警报消息的最佳方法

将此添加到您的
应用程序/views/layouts/application.html.erb
右上方的




这是我从

得到的,如果你是指javascript警报,你不能在你的控制器中使用javascript。你必须在你的视图中定义它。此外,JS警报很突兀,相反,如果用户转到特定路径并被迫登录:
def after\u sign\u in\u path\u for(资源)存储位置\u for(资源)| users\u dashboard\u path end
def after_sign_in_path_for(user)
  users_dashboard_path
end
  def after_sign_in_path_for(user)
    some_path
  end