[英]rails devise routing issue
I am new to rails and this is my first app. 我是Rails的新手,这是我的第一个应用程序。 Currently using rails 3.2.11 and devise 2.2.3 for authentication. 当前使用rails 3.2.11和设计2.2.3进行身份验证。
The problem is after signing in, the application returns 404 and says that it was not able to find a route for 'users' controller and 'show' action. 问题是登录后,应用程序返回404,并说它无法为“用户”控制器和“显示”操作找到路由。
I have a home controller for static pages and a user controller for the user. 我有一个用于静态页面的主控制器和一个用于用户的用户控制器。 I have generated the User model using the rails generate command. 我已经使用rails generate命令生成了User模型。 My config/routes.rb is as below. 我的config / routes.rb如下。
devise_for :users
resources :users
root :to => 'home#index'
Started POST "/users/sign_in" for 127.0.0.1 at 2013-01-29 15:44:25 +0530 Processing by Devise::SessionsController#create as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"cHXjNbgzEx2YsHX/AMb1oxjStY75IVHc9wT40NUOdJM=", "user"=>{"email"=>"r@e.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"} User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."email" = 'r@e.com' LIMIT 1 (0.1ms) begin transaction (0.5ms) UPDATE "users" SET "last_sign_in_at" = '2013-01-29 10:06:46.145781', "current_sign_in_at" = '2013-01-29 10:14:26.063767', "sign_in_count" = 66, "updated_at" = '2013-01-29 10:14:26.067024' WHERE "users"."id" = 1 (188.0ms) commit transaction Completed 404 Not Found in 365ms 在2013年1月29日15:44:25 +0530通过Devise :: SessionsController#create作为HTML参数开始处理127.0.0.1的POST“ / users / sign_in”:{“ utf8” =>“✓”,“ authenticity_token” =>“ cHXjNbgzEx2YsHX / AMb1oxjStY75IVHc9wT40NUOdJM =”,“ user” => {“ email” =>“ r@e.com”,“ password” =>“ [已过滤]”,“ remember_me” =>“ 0”},“ commit“ =>” Signin“}用户负载(0.4ms)选择” users“。* FROM” users“ WHERE” users“。” email“ ='r@e.com'LIMIT 1(0.1ms)开始交易( 0.5ms)UPDATE“ users” SET“ last_sign_in_at” ='2013-01-29 10:06:46.145781',“ current_sign_in_at” ='2013-01-29 10:14:26.063767',“ sign_in_count” = 66,“ updated_at “ ='2013-01-29 10:14:26.067024'WHERE” users“。” id“ = 1(188.0ms)提交事务在365ms内完成404找不到
ActionController::RoutingError (No route matches {:action=>"show", :controller=>"users"}): app/controllers/application_controller.rb:5:in `after_sign_in_path_for'
And I have modified the applications controller as below 我已经如下修改了应用程序控制器
def after_sign_in_path_for(resource)
user_url(resource)
end
What I am trying to do is that once the user logs in, I want to show the user specific information. 我想做的是,一旦用户登录,我想显示用户特定的信息。 For that I modified the after_sign_in_path_for(). 为此,我修改了after_sign_in_path_for()。 Any hints on how I can get the desired results? 关于如何获得所需结果的任何提示?
My rake routes output is below 我的耙路输出如下
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
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
root / home#index
You need on your application_controller.rb
您需要在application_controller.rb
def after_sign_in_path_for(resource)
user_url(current_user)
end
Take a look at https://github.com/plataformatec/devise/wiki/How-to%3A-redirect-to-a-specific-page-on-successful-sign-in-and-sign-out 看看https://github.com/plataformatec/devise/wiki/How-to%3A-redirect-to-a-specific-page-on-successful-sign-in-and-sign-out
Just try it on a clean installation of rails/devise and working properly. 只需在干净的rails / devise安装上尝试并正常工作即可。 I think you should have some redirection in users_controller.rb
and therefore does not work properly!. 我认为您应该在users_controller.rb
进行一些重定向,因此无法正常工作! Please remove any filter or redirect you have in your controllers and test that code 请删除控制器中的所有过滤器或重定向并测试该代码
Give a shot! 试一把!
Regards! 问候!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.