我需要帮助解决设计认证创业板的路由问题,以便在成功登录后重定向到自定义页面,以便通过输入测试人员姓名和年龄(测试数据)创建新记录。
我使用的是Rails 3和设计版本1.4.9
我的路线如下
new_user_session GET /users/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"}
user_session POST /users/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_user_session DELETE /users/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
user_password POST /users/password(.:format) {:action=>"create", :controller=>"devise/passwords"}
new_user_password GET /users/password/new(.:format) {:action=>"new", :controller=>"devise/passwords"}
edit_user_password GET /users/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
PUT /users/password(.:format) {:action=>"update", :controller=>"devise/passwords"}
cancel_user_registration GET /users/cancel(.:format) {:action=>"cancel", :controller=>"devise/registrations"}
user_registration POST /users(.:format) {:action=>"create", :controller=>"devise/registrations"}
new_user_registration GET /users/sign_up(.:format) {:action=>"new", :controller=>"devise/registrations"}
edit_user_registration GET /users/edit(.:format) {:action=>"edit", :controller=>"devise/registrations"}
PUT /users(.:format) {:action=>"update", :controller=>"devise/registrations"}
DELETE /users(.:format) {:action=>"destroy", :controller=>"devise/registrations"}
testers GET /testers(.:format) {:action=>"index", :controller=>"testers"}
POST /testers(.:format) {:action=>"create", :controller=>"testers"}
new_tester GET /testers/new(.:format) {:action=>"new", :controller=>"testers"}
edit_tester GET /testers/:id/edit(.:format) {:action=>"edit", :controller=>"testers"}
tester GET /testers/:id(.:format) {:action=>"show", :controller=>"testers"}
PUT /testers/:id(.:format) {:action=>"update", :controller=>"testers"}
DELETE /testers/:id(.:format) {:action=>"destroy", :controller=>"testers"}
root / {:controller=>"testers", :action=>"index"}在应用程序控制器中,我试图像下面这样覆盖这个方法,但是没有用,我仍然被路由回测试器索引。
class ApplicationController < ActionController::Base
protect_from_forgery
def after_sign_in_path_for(resource)
new_tester_path
end
end在我的routes.rb文件中,我有以下几行
Testing::Application.routes.draw do
devise_for :users
resources :testers
root :to => 'testers#index'虽然大部分代码都是在脚手架上完成的,但我仍然无法理解如何通过用户电子邮件和密码重定向到new_tester_path或路由/testers/新的之后成功的sign_in。
谁能让我知道我错过了什么……在编写覆盖函数时,我想知道需要指定的确切路径。
在测试时,我尝试了这样的愚蠢的东西,但是google页面也没有打开.
class ApplicationController < ActionController::Base
protect_from_forgery
helper ApplicationHelper
def after_sign_in_path_for(resource)
"www.google.com"
end
def after_sign_up_path_for(resource)
"www.google.com"
end
def after_update_path_for(resource)
"www.google.com"
end 发布于 2012-10-12 07:47:56
只需使用以下片段:
class ApplicationController < ActionController::Base
def after_sign_in_path_for(user)
user_url(user)
end
end发布于 2011-11-23 00:05:49
尝试在会话中设置user_return_to路径:
session['user_return_to'] = new_tester_path您可以在从Devise::SessionsController派生的控制器中执行此操作。
发布于 2018-01-31 22:07:47
Devise解释了中的成功标志重定向到特定页面。的所有步骤。通过将这些技术结合起来,您可以在成功登录后将用户重定向到许多地方。
这是简历:
您可以在从Devise::SessionsController继承的控制器中执行此操作-首先,在控制器/用户/会话_控制器中: do:
module Users
class SessionsController < Devise::SessionsController
def new
if params[:redirect_to].present?
self.resource = resource_class.new(sign_in_params)
store_location_for(resource, params[:redirect_to])
end
super
end
end
end在config/职业道德In中,您还应该添加:
devise_for :users, controllers: {sessions: 'users/sessions'}而且您必须在您的after_sign_in_path_for中添加一个自定义ApplicationController。
class ApplicationController < ActionController::Base
protected
def after_sign_in_path_for(resource)
stored_location_for(resource) || root_path
end
end据我所知,这在所有的设计版本中都是有效的。
https://stackoverflow.com/questions/8234023
复制相似问题