gpt4 book ai didi

ruby-on-rails - 设计 after_sign_in_path_for ... 发送到 .... root_path - 查询

转载 作者:行者123 更新时间:2023-12-03 21:18:17 25 4
gpt4 key购买 nike

我需要有关设计身份验证 gem 的路由问题帮助,以便在成功登录后重定向到自定义页面,以便通过输入测试人员姓名和年龄(测试数据)来创建新记录

我正在使用 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"}

在应用程序 Controller 中,我尝试覆盖如下所示的方法,但无济于事,我仍然被路由回测试器索引
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/new 登录成功通过用户电子邮件和密码。

有人可以让我知道我缺少什么..... 在编写覆盖功能时,我想知道我需要指定的确切路线。

在测试时,我尝试了一些愚蠢的事情,但谷歌页面也没有打开...... :(
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

最佳答案

只需使用此代码段:

class ApplicationController < ActionController::Base
def after_sign_in_path_for(user)
user_url(user)
end
end

关于ruby-on-rails - 设计 after_sign_in_path_for ... 发送到 .... root_path - 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8234023/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com