【发布时间】:2014-02-25 05:27:59
【问题描述】:
当我尝试访问我的 /users/sign_up 页面时,我收到“太多重定向”
设计 + MongoMapper + Rails 3.2.13
耙路线:
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
new_user_session GET /users/login(.:format) devise/sessions#new
user_session POST /users/login(.:format) devise/sessions#create
destroy_user_session DELETE /users/logout(.:format) devise/sessions#destroy
user_password POST /users/reset(.:format) devise/passwords#create
new_user_password GET /users/reset/new(.:format) devise/passwords#new
edit_user_password GET /users/reset/edit(.:format) devise/passwords#edit
PUT /users/reset(.: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
root / customers#index
customers GET /customers(.:format) customers#index
POST /customers(.:format) customers#create
new_customer GET /customers/new(.:format) customers#new
edit_customer GET /customers/:id/edit(.:format) customers#edit
customer GET /customers/:id(.:format) customers#show
PUT /customers/:id(.:format) customers#update
DELETE /customers/:id(.:format) customers#destroy
Rails 服务器控制台一遍又一遍地吐出这个:
Started GET "/users/sign_in" for 127.0.0.1 at 2014-02-24 21:10:01 -0800
Processing by UsersController#show as HTML
Parameters: {"id"=>"sign_in"}
Completed 401 Unauthorized in 0ms
我在他们的自述文件中读到,Devise 应该在我的控制器中创建一些辅助方法 - 除了生成器的标准 7 之外,我什么也没看到。
似乎它试图以“sign_in”身份登录,我当然没有指示它这样做 - 这是一个全新的 Rails 应用程序,基本上只有一个模型 - 用户 - 和一个模型 - 客户 - 绝对没有数据或任何其他文件。从字面上看,只是试图让这个 Devise 登录页面呈现 - 或注册页面 - 或任何页面。
这是我现在的整个 routes.rb 文件:
resources :users
devise_for :users
root :to => "customers#index"
resources :customers
当我有 before_filter authenticate_user 时会发生这种情况!在我的用户控制器中
因此,当我删除该行时 - 我只是尝试点击 /users/sign_up - 我得到以下信息:
No route matches {:action=>"edit", :controller=>"users", :id=>nil}
应该重定向到这里:
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
控制器动作是:
def edit
@user = User.find(params[:id])
end
当然 - 因为我的数据库中根本没有任何东西 - @user 现在为零 - 这就是问题吗?
人们如何开始设计?我从来没有成功地让这个愚蠢的东西发挥作用。
【问题讨论】:
-
好吧,答案是 devise_for :users 应该是在 routes.rb 中的资源 :users 之上。我从建议的阅读中发现,StackOverflow 在我设置标题并即将保存它时向我展示了正确的内容 - 因此其他人可以将其作为答案发布并获得信用:)
标签: ruby-on-rails-3 mongodb authentication devise mongomapper