gpt4 book ai didi

ruby-on-rails - 注册后设计重定向

转载 作者:行者123 更新时间:2023-12-03 13:16:47 24 4
gpt4 key购买 nike

设计让我很难受。目前,除了注册重定向以外,其他所有功能似乎都可以正常工作。我希望设计人员在注册或登录时(登录确实有效),在索引操作时重定向到我的城镇管理员。

我试过重写RegistrationsController,并尝试添加一个applicationController函数,例如:

  def after_sign_in_path_for(resource_or_scope)
if resource_or_scope.is_a?(User)
town_path
else
super
end
end

不过,我遇到了同样的错误:
NoMethodError in User/townController#index

You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.*

严重的是,我找不到办法。有什么想法吗? :)

编辑:我的路线
      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 GET /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"}
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"}
root /(.:format) {:action=>"index", :controller=>"home"}
user_root /user(.:format) {:action=>"index", :controller=>"user/town"}
home /home(.:format) {:action=>"index", :controller=>"home"}
town /town(.:format) {:action=>"index", :controller=>"town"}
inbox /messages(.:format) {:action=>"index", :controller=>"messages"}
inbox /messages/inbox(.:format) {:action=>"inbox", :controller=>"messages"}

Routes.rb:
  devise_for :users

root :to => "home#index"

namespace :user do
root :to => "town#index"
end

scope :path => '/home', :controller => :home do
match '/' => :index, :as => 'home'
end

scope :path => '/town', :controller => :town do
match '/' => :index, :as => 'town'
end
......

最佳答案

这就是我的工作方式。

# In your routes.rb
match 'dashboard' => 'user_dashboard#index', :as => 'user_root'

然后确保没有在 before_filter :authenticate_user! Controller 上设置 home#index

关于ruby-on-rails - 注册后设计重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4987841/

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