Q:

after_sign_in_path_for

I use devise in my application.
I want to pop-up a welcome message while the user login.
so in my application_controller.erb I defined:
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

when I tried to sign-in to my app, I got an error:
ArgumentError in Devise::SessionsController#create

wrong number of arguments (1 for 0)
Rails.root: /home/alon/alon/todolist

Application Trace | Framework Trace | Full Trace
app/controllers/application_controller.rb:14:in `after_sign_in_path_for'

A:

By default devise adds flash messages. No need to set the flash message.Just you need to display the flash message in the view. Try the below code.
in your app/views/layouts/application.html.erb
<% flash.each do |type, message| %>
  <div class="flash">
     <%= message %>
  </div>        
<% end %> 

FYI after_sign_in_path_for is not for setting the flash message. Its the just to inform the path to devise where you want to redirect the application after successful login.
Lets set the successful login redirect path
in you config/routes.rb
match "users/dashboard" => "controllername#action"

And finally change the after_sign_in_path_for method
def after_sign_in_path_for(user)
  users_dashboard_path
end

