避免在root_path设计验证flash消息 [英] Avoid devise validation flash message at root_path
问题描述
I18n-Flash-Message-with-Devise-and-Bootstrap
routes.rb
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
当我尝试访问 localhost:3000
,我将指向 localhost:3000 / users / sign_in
,这是正常的,因为 filter
,但是我会得到一个验证信息
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
如何避免这种情况?
我尝试使用
I tried changing by using match
in routes that didn't help out.
编辑:
考虑一个场景:
(没有用户会话)如果我尝试访问/角色将被重定向到登录路径,那时我需要msg。或者我会放弃其他闪存验证,如退出,电子邮件存在,pwd错误。
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.
推荐答案
告诉应用程序使用root作为会话#如果用户未登录,则为新增
Tell Application to use root as sessions#new if user not logged-in
config / routes.rb
config/routes.rb
authenticated :user do
root :to => "users#index"
end
unauthenticated :user do
devise_scope :user do
get "/" => "devise/sessions#new"
end
end
这篇关于避免在root_path设计验证flash消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!