Ruby on rails 轨道&x2B;设计:重定向到用户资源

Ruby on rails 轨道&x2B;设计:重定向到用户资源,ruby-on-rails,devise,Ruby On Rails,Devise,当我的应用程序\u controller.rb重定向到用户\u路径时,如下所示: def after_sign_in_path_for(resource) users_path end def after_sign_in_path_for(resource) @user = User.find(params[:id]) user_path(@user) end 重定向有效。但如果我将其更改为user\u path: def after_sign_in_path_for

当我的
应用程序\u controller.rb
重定向到
用户\u路径时,如下所示:

def after_sign_in_path_for(resource)
    users_path
end
def after_sign_in_path_for(resource)
    @user = User.find(params[:id])
    user_path(@user)
end
重定向有效。但如果我将其更改为
user\u path

def after_sign_in_path_for(resource)
    user_path
end
我得到一个路由错误。这是我的路线。rb:

devise_for :users
get "users/show"

resources :orders

resources :users do
    resources :orders
end
我想也许我应该像这样传递用户ID:

def after_sign_in_path_for(resource)
    users_path
end
def after_sign_in_path_for(resource)
    @user = User.find(params[:id])
    user_path(@user)
end

但是错误回来了
找不到没有ID的用户
。帮助?

我想您应该在登录后尝试
当前用户

user_path(current_user)

我花了几个小时试图获得相同的功能,这是ApplicationController中的代码,它最终为我工作:

def after_sign_in_path_for(resource)
    current_user
end
如果我尝试过
当前用户路径
,我总是会遇到
未定义的局部变量或方法当前用户路径
错误

此外,我正在使用Rails 3.2.8和Desive 2.1.2

希望有帮助