首页 > Rails项目中如何将devise的登录页面作为系统首页?

Rails项目中如何将devise的登录页面作为系统首页?

在一个类似微博系统的项目中,用户权限控制部分使用Devise,在Devise配置好后,如何将系统首页设置成Devise的登录页面?实现在系统root页面呈现一个登录表单,在root页面直接可以登录?


class ApplicationController < ActionController::Base
    before_filter :authenticate_admin!
end

That's it!
不管你在哪个页面,只要你没登录,你都得去登录!


devise_for :users

devise_scope :user do
  authenticated :user do
    root 'home#index', as: :authenticated_root
  end

  unauthenticated do
    root 'devise/sessions#new', as: :unauthenticated_root
  end
end

这样子就可以了,未登录先显示登录页,登录之后显示你的登录后主页。


root :to => "devise/sessions#new"

把root 设置成devise登录controller就可以

另外可以看下这个 http://stackoverflow.com/questions/4954876/setting-devise-login-to-be-root-page

【热门文章】
【热门文章】