现在在这个上挣扎了几个小时。在最初制作自己的身份验证系统后,我已将 Devise gem 集成到我的 Rails 项目中,但我遇到了一个我无法理解的问题。
当用户登录该方法时:
def after_sign_in_path_for(resource_or_scope)
user = resource_or_scope
user_path(user.username)
end
被触发以将用户重定向到他们的个人资料。
我有一个编辑用户路线,它将用户带到一个页面,他们可以在其中编辑他们的详细信息并添加“想要的项目”。两个单独的表单,带有两个单独的控制器和操作。
“添加想要的项目”方法发布到不同的控制器,该控制器呈现调用的视图WantsController
并通过关联为用户添加想要的项目。
由于某种原因,after_sign_in_path_for
在提交此表单时调用了该方法?和登录没关系...
这是我的路线:
#users/auth
devise_for :users, :skip => [:sessions, :registrations]
devise_scope :user do
# registration
get "/signup", to: "users#new", as: :sign_up
post "/signup", to: "users#create", as: :sign_up_create
# account
get "/:username/account", to: "users#edit", as: :user_account
put "/users/:id", to: "users#update", as: :user_update
# shows
get "/:username", to: "users#show", as: :user
get "/:username/interests", to: "users#interests", as: :user_interests
get "/:username/offers", to: "users#offers", as: :user_offers
get "/:username/trades", to: "users#trades", as: :user_trades
# auth
post "/signin" => 'devise/sessions#create', as: :sign_in
delete "/signout", to: "devise/sessions#destroy", as: :sign_out
#wants
resources :wants, only: [:create, :destroy]
end
如果我将wants
资源放在设计范围之外(我期望它应该去的地方),我会收到以下信息:
找不到路径“/想要”的设计映射
这里发生了什么事?难倒!
谢谢。