使用用户ID设计路由中的未定义方法

时间:2015-10-15 20:29:45

标签: ruby-on-rails ruby ruby-on-rails-3 devise

目前我有一个典型的设计安装,但我已将用户ID添加到具有current_user可用的路由。但是在尝试登录该服务时,我收到了下面所述的错误。

错误

NameError in Devise::SessionsController#create

undefined local variable or method `offers_path' for #<Devise::SessionsController:0x007f0e80ec7a08>

  def after_sign_in_path_for(resource)
    offers_path
  end

的routes.rb

devise_for :users

resources :users do
  resources :offers do
    member do
       put :tourcomplete
    end   
  end
end

Rake Routes

 tourcomplete_user_offer PUT    /users/:user_id/offers/:id/tourcomplete(.:format) offers#tourcomplete
             user_offers GET    /users/:user_id/offers(.:format)                  offers#index
                         POST   /users/:user_id/offers(.:format)                  offers#create
          new_user_offer GET    /users/:user_id/offers/new(.:format)              offers#new
         edit_user_offer GET    /users/:user_id/offers/:id/edit(.:format)         offers#edit
              user_offer GET    /users/:user_id/offers/:id(.:format)              offers#show
                         PATCH  /users/:user_id/offers/:id(.:format)              offers#update
                         PUT    /users/:user_id/offers/:id(.:format)              offers#update
                         DELETE /users/:user_id/offers/:id(.:format)              offers#destroy
                   users GET    /users(.:format)                                  users#index
                         POST   /users(.:format)                                  users#create

不太确定这是否是将用户ID放入已登录路由的最佳方式。在这个问题上会有任何帮助。

1 个答案:

答案 0 :(得分:1)

查看您的路线,您没有任何offers_path,但您正试图使用​​它,这就是您收到此错误的原因。

您应该尝试使用user_offers_path代替并传递user作为参数,如下所示:

user_offers_path(@user)