Rails 3 子域
我想将我的应用程序发布给一组选定的个人以进行私人测试。我为此任务创建了一个子域:beta.company.com。
该应用程序在我的工作站上按预期运行,但当我将其推送到服务器时,该应用程序会不断路由回身份验证页面。仅供参考,我正在使用声明性授权、authlogic 和 Passenger。
routes.rb:
#Application controller
match "/not_authorized", :to => "application#not_authorized", :as => :not_authorized
#UserSessions controller
match "/quit", :to => "user_sessions#destroy", :as => :quit
match "/authenticate", :to => "user_sessions#new", :as => :authenticate
resources :user_sessions, :only => :create
#Users controller
match "/enroll", :to => "users#new", :as => :enroll
# root url
root :to => "users#index"
症状:
- 匿名路由(例如 user_sessions#create、not_authorized)按匿名方式正常工作。用户
- 应用程序在我的工作站上按预期运行
当我查看 production.log 时,我看到如下条目:
由 UsersController#index 作为 HTML 进行处理 权限被拒绝:未找到 # @role_symbols=[:guest]> 索引的匹配规则(角色 [:guest],权限 [:index, :read, :manage],上下文 :users)。 重定向到 http://beta.company.com/authenticate
** 编辑 **
对于一个,没有 UsersController#index 操作,如果有,匿名用户将无法访问它。我很困惑为什么它试图路由到那里(而不是根 URL,这是成功身份验证后它应该去的地方)。
这似乎是一个特定于子域的路由问题,但我不能确定。
更仔细地重新阅读这个“错误”。有一个 UserController#index 操作,并且匿名用户不应该有权访问它。乍一看,我以为它读的是 UserSessionController#index,这是不存在的操作。
现在,经过身份验证的用户似乎没有被创建或保存,因此被重新路由回 UserSession#new 操作(也称为身份验证路径)。
** / 编辑 **
** 编辑 II **
我从 cookie_store 更改为 active_record_store:
# cookie store
# MyApp::Application.config.session_store :cookie_store, :key => '_myApp_session'
# active-record store
MyApp::Application.config.session_store :active_record_store
添加了表 ($ rake db:sessions:create),进行了迁移 ($ rake db:migrate),重新启动了 Apache ($ touch tmp/ restart.txt),清除浏览器缓存,然后重新启动浏览器。
会话已成功添加到会话表中,但我仍然遇到问题。
** / 编辑 II **
非常感谢您的想法。
I would like to publish my application to a selected set of individuals for a private beta. I created a sub-domain for this task: beta.company.com.
The application operates as expected on my workstation, but when I push it to the server, the application continually routes back to the authentication page. FYI, I'm using declarative-authorization, authlogic, and Passenger.
routes.rb:
#Application controller
match "/not_authorized", :to => "application#not_authorized", :as => :not_authorized
#UserSessions controller
match "/quit", :to => "user_sessions#destroy", :as => :quit
match "/authenticate", :to => "user_sessions#new", :as => :authenticate
resources :user_sessions, :only => :create
#Users controller
match "/enroll", :to => "users#new", :as => :enroll
# root url
root :to => "users#index"
Symptoms:
- anonymous routes (e.g. user_sessions#create, not_authorized) work as expected for anon. user
- the application operates as expected on my workstation
When I look at the production.log, I see an entry like:
Processing by UsersController#index as HTML
Permission denied: No matching rules found for index for # @role_symbols=[:guest]> (roles [:guest], privileges [:index, :read, :manage], context :users).
Redirected to http://beta.company.com/authenticate
** edit **
For one, there isn't a UsersController#index action, and if there was, the anonymous user wouldn't have access to it. I'm confused to why it is trying to route there at all (instead of the root url, which is where it should go after a successful authentication).
This seems like a sub-domain-specific routing issue, but I can't be sure.
re-read this 'error' more closely. there is a UserController#index action AND the anonymous user should NOT have access to it. at first glance, i thought it read UserSessionController#index, which is the action that doesn't exist.
now, it seems like the authenticated user isn't being created or saved and consequently, is being re-routed back to UserSession#new action (AKA authenticate path).
** / edit **
** edit II **
I changed from cookie_store to active_record_store:
# cookie store
# MyApp::Application.config.session_store :cookie_store, :key => '_myApp_session'
# active-record store
MyApp::Application.config.session_store :active_record_store
Added the table ($ rake db:sessions:create), did the migration ($ rake db:migrate), restarted Apache ($ touch tmp/restart.txt), cleared the browser's cache, then restarted the browser.
The session was added to the sessions table successfully, but I still get the problem.
** / edit II **
Thoughts are greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于初学者来说……
您的根 URL 是 UsersController#index:
检查以确保您在 beta 域上设置 cookie。您可能正在重定向或设置使用完整 URL(而不仅仅是路径,因此
user_url(@user)
与user_path(@user)
)的链接,这会导致您将直接前往根域。For starters…
Your root URL is UsersController#index:
Check to make sure you are setting the cookie on the beta domain. You might be redirecting or setting links that use the full URL (rather than just the path, so
user_url(@user)
vsuser_path(@user)
), which would cause you to be headed straight for the root domain.该问题与控制器中的 SELECT 语句有关。 SELECT 语句“SELECT Users.*”中表名区分大小写导致错误。由于某种原因,该错误未包含在 production.log 文件中。随后的部署(不使用 Capistrano)做了一些事情(我仍然不知道是什么)来使此错误包含在 production.log 文件中。
现在,如果我能确定那个“东西”是什么......
The issue was related to a SELECT statement in the controller. The case-sensitivity of the table name in the SELECT statement, "SELECT Users.*", was causing an error. For some reason, this error was not being included in the production.log file. A subsequent deployment, not using Capistrano, did something (I still don't know what) to enable this error to be included in the production.log file.
Now, if I could just determine what that 'something' was...