Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid devise validation flash message at root_path

I18n-Flash-Messages-with-Devise-and-Bootstrap

routes.rb

root :to => 'users#index'
  devise_for :users, :controllers => {:registrations => "registrations", :sessions => "sessions"}
  devise_for :users do
    get '/users/sign_in', :to => 'devise/sessions#new', :as => :new_user_session
    get '/users/sign_out', :to => 'devise/sessions#destroy', :as => :destroy_user_session
    get "/users/sign_up", :to => "registrations#new"
  end

When I try to access localhost:3000, I will directed to localhost:3000/users/sign_in and that's normal, because of filter, but however I will get a validation message

You need to sign in or sign up before continuing

How to avoid this?

I tried changing by using match in routes that didn't help out.

Edit: Consider a scenario: (without user session) if I try to access /roles will be redirected to sign in path, at that point I would require msg. or I would loose other flash validations such as sign-out, email-exists, pwd wrong.

like image 593
Nithin Avatar asked Apr 17 '26 17:04

Nithin


1 Answers

Tell Application to use root as sessions#new if user not logged-in

config/routes.rb

authenticated :user do
    root :to => "users#index"
  end
  unauthenticated :user do
    devise_scope :user do
      get "/" => "devise/sessions#new"
    end
  end
like image 147
devudilip Avatar answered Apr 19 '26 10:04

devudilip