在Rails应用程序的生产环境中重定向到登录页面



如何在Rails应用程序上编程地将我的所有请求重新路由到生产中的登录页面,同时保持对开发中的其他匿名访问页面的访问。

例如,如果我有一个请求www.mywebsite.com/listings,我想在开发中显示它们,但将其重定向到生产中的登录页面,主要目的是保持我的应用程序在隐形模式,直到发布。

是否有最好的众所周知的方法来做到这一点,因为我认为这是一个非常普遍的问题?

在你的应用程序控制器中…

before_filter :stealth_mode
def stealth_mode
    redirect_to login_url if Rails.env.production?
end

在你的登录控制器

skip_before_filter :stealth_mode

给你!: -)

在你的路由:

if Rails.env.production?
  match '(:controller(/:action(/:id(.:format))))' => "root_controller#root_action"
else
  #your routes declarations
end
root :to => "root_controller#root_action"

最新更新