新手问题 经如主页时出现多重重定向,如何排查

limkurn · 2013年04月14日 · 最后由 limkurn 回复于 2013年04月14日 · 2739 次阅读

我在rake routes后结果如下

 root        /                                                projects#index
        new_user_session GET    /users/sign_in(.:format)                         devise/sessions#new
            user_session POST   /users/sign_in(.:format)                         devise/sessions#create
    destroy_user_session DELETE /users/sign_out(.:format)                        devise/sessions#destroy
           user_password POST   /users/password(.:format)                        devise/passwords#create
       new_user_password GET    /users/password/new(.:format)                    devise/passwords#new
      edit_user_password GET    /users/password/edit(.:format)                   devise/passwords#edit
                         PUT    /users/password(.:format)                        devise/passwords#update
cancel_user_registration GET    /users/cancel(.:format)                          devise/registrations#cancel
       user_registration POST   /users(.:format)                                 devise/registrations#create
   new_user_registration GET    /users/sign_up(.:format)                         devise/registrations#new
  edit_user_registration GET    /users/edit(.:format)                            devise/registrations#edit
                         PUT    /users(.:format)                                 devise/registrations#update
                         DELETE /users(.:format)                                 devise/registrations#destroy
              admin_root        /admin(.:format)                                 admin/base#index
             admin_users GET    /admin/users(.:format)                           admin/users#index
                         POST   /admin/users(.:format)                           admin/users#create
          new_admin_user GET    /admin/users/new(.:format)                       admin/users#new
         edit_admin_user GET    /admin/users/:id/edit(.:format)                  admin/users#edit
              admin_user GET    /admin/users/:id(.:format)                       admin/users#show
                         PUT    /admin/users/:id(.:format)                       admin/users#update
                         DELETE /admin/users/:id(.:format)                       admin/users#destroy
       admin_permissions GET    /admin/permissions(.:format)                     admin/permissions#index
                         POST   /admin/permissions(.:format)                     admin/permissions#create
    new_admin_permission GET    /admin/permissions/new(.:format)                 admin/permissions#new
   edit_admin_permission GET    /admin/permissions/:id/edit(.:format)            admin/permissions#edit
        admin_permission GET    /admin/permissions/:id(.:format)                 admin/permissions#show
                         PUT    /admin/permissions/:id(.:format)                 admin/permissions#update
                         DELETE /admin/permissions/:id(.:format)                 admin/permissions#destroy
            confirm_user GET    /awaiting_confirmation(.:format)                 users#confirmation
 update_user_permissions PUT    /admin/user/:user_id/permissions(.:format)       admin/permissions#update
         project_tickets GET    /projects/:project_id/tickets(.:format)          tickets#index
                         POST   /projects/:project_id/tickets(.:format)          tickets#create
      new_project_ticket GET    /projects/:project_id/tickets/new(.:format)      tickets#new
     edit_project_ticket GET    /projects/:project_id/tickets/:id/edit(.:format) tickets#edit
          project_ticket GET    /projects/:project_id/tickets/:id(.:format)      tickets#show
                         PUT    /projects/:project_id/tickets/:id(.:format)      tickets#update
                         DELETE /projects/:project_id/tickets/:id(.:format)      tickets#destroy
                projects GET    /projects(.:format)                              projects#index
                         POST   /projects(.:format)                              projects#create
             new_project GET    /projects/new(.:format)                          projects#new
            edit_project GET    /projects/:id/edit(.:format)                     projects#edit
                 project GET    /projects/:id(.:format)                          projects#show
                         PUT    /projects/:id(.:format)                          projects#update
                         DELETE /projects/:id(.:format)                          projects#destroy

结果显示主页不是projects#index 怎么会出现http://localhost:3000/ 的网页生成了 过多的重定向。清除此网站的 Cookie 或允许第三方 Cookie 可能会解决该问题。如果 不能解决,可能是服务器配置有问题,而不是您的 计算机有问题。

projects#index 的代码贴出来看一下,若是我没猜错的话,你应该是遇到了multiple render / redirect error 这类的问题。

#1 楼 @nightire

 def index
   @projects = Project.for(current_user).all
  end

private
  def find_project
   @project = Project.for(current_user).find(params[:id])
   rescue ActiveRecord::RecordNotFound
    flash[:alert] = "The project you were looking" + "for could not be found"
    redirect_to root_path
  end

  def self.for(user)
   user.admin? ? Project : project.readable_by(user)
  end
需要 登录 后方可回复, 如果你还没有账号请 注册新账号