关于Rails:成功登录后重定向到设备控制器

Redirecting to the devise controller after successfull login

我是Ruby On Rails的新手。我正在使用devise gem制作应用程序。我的要求是成功登录后,我应该再次重定向到devise控制器。

我已将devise控制器创建为"用户"

我还创建了一个用于重定向的控制器home_controller.rb
home控制器下,我已经对此进行了编码。

1
2
3
4
5
def index
  if user_signed_in?
    redirect_to :controller => 'users', :action =>add
  end
end

我在users_controller.rb

下编写了add方法

routes.rb下,我已经对此进行了编码

1
2
3
devise_for :users, controllers:{sessions:"users/sessions"}
root :to => 'home#index'
match 'users/:action' => 'users#add', :as => :add

但是它没有重定向。我应该怎么办。任何帮助。谢谢


尝试一下:-

1
2
3
4
5
resources :users do
  member do
    get"add"
  end
end


如果我的理解正确,您将希望使用Devise重定向帮助器:

1
2
3
4
5
6
#app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
   def after_sign_in_path_for(resource)
      user_add_path
   end
end

我不知道是这样的:

I should redirect to devise controller again

设备控制器分为SessionsControllerRegistrationsControllerPasswordsControllerConfirmationsController