2014-02-21 111 views
0

林有一個問題是關於我的路線。使用im設計,但我也有定製的控制器,以允許管理員編輯用戶設置。RoutingError(無路由匹配[PUT]

對我來說,一切工作在發展精細但是當我部署到我的託管服務器的東西不工作,因爲他們應該。

問題我有如下,當一個管理更新用戶,我得到一個路由錯誤。這工作正常本地,但在託管服務器上我得到以下

Started PUT "https://stackoverflow.com/users/4" at Fri Feb 21 04:08:14 -0500 2014 
ActionController::RoutingError (No route matches [PUT] "/4"): 
    actionpack (3.2.2) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'> actionpack (3.2.2) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call' 
    railties (3.2.2) lib/rails/rack/logger.rb:26:in `call_app' 
    railties (3.2.2) lib/rails/rack/logger.rb:16:in `call' 
    actionpack (3.2.2) lib/action_dispatch/middleware/request_id.rb:22:in `call' 

什麼不能t看起來對我來說,「/ users/4」是如何被降低到「/ 4」的。剩下的路徑發生了什麼?

我的路線看起來很好

users POST /users(.:format) users/registrations#create 
     new_user_session GET /users/sign_in(.:format)     devise/sessions#new 
      user_session POST /users/sign_in(.:format)     devise/sessions#create 
    destroy_user_session DELETE /users/sign_out(.:format)     devise/sessions#destroy 
      user_password POST /users/password(.:format)     devise/passwords#create 
     new_user_password GET /users/password/new(.:format)    devise/passwords#new 
     edit_user_password GET /users/password/edit(.:format)   devise/passwords#edit 
         PUT /users/password(.:format)     devise/passwords#update 
cancel_user_registration GET /users/cancel(.:format)     users/registrations#cancel 
     user_registration POST /users(.:format)       users/registrations#create 
    new_user_registration GET /users/sign_up(.:format)     users/registrations#new 
    edit_user_registration GET /users/edit(.:format)      users/registrations#edit 
         PUT /users(.:format)       users/registrations#update 
         DELETE /users(.:format)       users/registrations#destroy 
     new_user_session GET /users/sign_in(.:format)     devise/sessions#new 
         POST /users/sign_in(.:format)     devise/sessions#create 
    destroy_user_session DELETE /users/sign_out(.:format)     devise/sessions#destroy 
         POST /users/password(.:format)     devise/passwords#create 
         GET /users/password/new(.:format)    devise/passwords#new 
         GET /users/password/edit(.:format)   devise/passwords#edit 
         PUT /users/password(.:format)     devise/passwords#update 
         GET /users/cancel(.:format)     devise/registrations#cancel 
         POST /users(.:format)       devise/registrations#create 
         GET /users/sign_up(.:format)     devise/registrations#new 
         GET /users/edit(.:format)      devise/registrations#edit 
         PUT /users(.:format)       devise/registrations#update 
         DELETE /users(.:format)       devise/registrations#destroy 
         GET /users(.:format)       users#index 
         POST /users(.:format)       users#create 
       new_user GET /users/new(.:format)      users#new 
       edit_user GET /users/:id/edit(.:format)     users#edit 
        user GET /users/:id(.:format)      users#show 
         PUT /users/:id(.:format)      users#update 
         DELETE /users/:id(.:format)      users#destroy 

正如你可以看到用戶更新路徑存在

PUT /users/:id(.:format)用戶#更新

主機服務器使用乘客,導軌3.2.X,紅寶石1.8.7。我知道3.2.x版存在安全問題,但這只是我的一個愛好。

路由配置

resources :comm_channels 

devise_for :users, :controllers => { :registrations => "users/registrations" } do 
    post '/users', :to => 'users/registrations#create' 
end 

devise_for :users 

resources :users,:roles,:news ,:invites, :clubs, :events, :albums, :pictures, :static_pages, :sponsors 

match "static_pages/:action/:pagetype", :controller => "static_pages" 
match 'invites/edit(/:eid/:iid/:code)' => 'invites#edit', :as => :invite_confirm 
match 'events/:id/reminder' => 'events#reminder', :as => :event_reminder 
match 'events/:id/republish' => 'events#republish', :as => :event_republish 
match 'roles/resetMembership' => 'roles#resetMembership', :as => :reset_membership 
match 'roles/membership_reminder' => 'roles#membership_reminder', :as => :membership_reminder 

root :to => "static_pages#show#home" 

更新2

登上香港專業教育學院採取蒂姆斯的意見和清理我的文件航線不過IM仍然能看到同樣的問題。

我的路線,如今看起來像

resources :comm_channels 

devise_for :users,:path => 'club_users', :controllers => { :registrations => "users/registrations" } do 
    post '/users', :to => 'users/registrations#create' 
end 


resources :users 

resources :roles,:news ,:invites, :clubs, :events, :albums, :pictures, :static_pages, :sponsors 

match "static_pages/:action/:pagetype", :controller => "static_pages" 
match 'invites/edit(/:eid/:iid/:code)' => 'invites#edit', :as => :invite_confirm 
match 'events/:id/reminder' => 'events#reminder', :as => :event_reminder 
match 'events/:id/republish' => 'events#republish', :as => :event_republish 
match 'roles/resetMembership' => 'roles#resetMembership', :as => :reset_membership 
match 'roles/membership_reminder' => 'roles#membership_reminder', :as => :membership_reminder 

root :to => "static_pages#show#home" 

路線輸出如下

 users POST /users(.:format)       users/registrations#create 
     new_user_session GET /club_users/sign_in(.:format)    devise/sessions#new 
      user_session POST /club_users/sign_in(.:format)    devise/sessions#create 
    destroy_user_session DELETE /club_users/sign_out(.:format)   devise/sessions#destroy 
      user_password POST /club_users/password(.:format)   devise/passwords#create 
     new_user_password GET /club_users/password/new(.:format)  devise/passwords#new 
     edit_user_password GET /club_users/password/edit(.:format)  devise/passwords#edit 
         PUT /club_users/password(.:format)   devise/passwords#update 
cancel_user_registration GET /club_users/cancel(.:format)    users/registrations#cancel 
     user_registration POST /club_users(.:format)      users/registrations#create 
    new_user_registration GET /club_users/sign_up(.:format)    users/registrations#new 
    edit_user_registration GET /club_users/edit(.:format)    users/registrations#edit 
         PUT /club_users(.:format)      users/registrations#update 
         DELETE /club_users(.:format)      users/registrations#destroy 
         GET /users(.:format)       users#index 
         POST /users(.:format)       users#create 
       new_user GET /users/new(.:format)      users#new 
       edit_user GET /users/:id/edit(.:format)     users#edit 
        user GET /users/:id(.:format)      users#show 
         PUT /users/:id(.:format)      users#update 
         DELETE /users/:id(.:format)      users#destroy 

我仍然看到在產品設置了同樣的錯誤。

Started PUT "https://stackoverflow.com/users/21" for 194.XXXX at Sun May 11 08:05:48 -0400 2014 

ActionController::RoutingError (No route matches [PUT] "/21"): 
    actionpack (3.2.2) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call' 
    actionpack (3.2.2) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call' 
    railties (3.2.2) lib/rails/rack/logger.rb:26:in `call_app' 
    railties (3.2.2) lib/rails/rack/logger.rb:16:in `call' 
    actionpack (3.2.2) lib/action_dispatch/middleware/request_id.rb:22:in `call' 
    rack (1.4.5) lib/rack/methodoverride.rb:21:in `call' 
    rack (1.4.5) lib/rack/runtime.rb:17:in `call' 
    activesupport (3.2.2) lib/active_support/cache/strategy/local_cache.rb:72:in `call' 
    rack (1.4.5) lib/rack/lock.rb:15:in `call' 
    actionpack (3.2.2) lib/action_dispatch/middleware/static.rb:61:in `call' 

香港專業教育學院嘗試不同的也是最簡單的變化e.g

devise_for :users,:path => 'club_users' 
resources :users 

而且還逆向

devise_for :users 
resources :users, :path => 'useradmin' 

沒有喜悅。正如我耙路線之前說的告訴我它有

PUT /users/:id(.:format)      users#update 

但某處沿線,PUT「/用戶/ 21」被剝離下來「/ 21」。

任何想法?

+0

請添加您的/config/routes.rb – krabbi

+0

路線已被添加。 – JBOnThePc

+0

嗯,我沒有線索,我不記得我曾經遇到過這種行爲。也許別人有任何想法。請檢查它是否出現在其他路線上,或者只是「放置用戶」。在本地你運行webrick或瘦或類似的東西? – krabbi

回答

0

我不確定爲什麼只有特定的路線給你帶來麻煩,只有在生產中,但我認爲你的路線存在一些普遍的問題,如果你解決了問題,可能會解決特定路線的問題。

首先,你必須:

devise_for :users, :controllers => { :registrations => "users/registrations" } do 
    post '/users', :to => 'users/registrations#create' 
end 

devise_for :users 

你可以從你的路線看,這種重複的devise_for導致大部分的路線是,除了對於其有各自的兩個副本的註冊路線重複的路線; (因爲第一個devise_for),其中一半去設計的註冊控制器(因爲第二個devise_for。你應該只有一個devise_for。你保留哪一個取決於你想要哪個註冊控制器假設你希望他們使用你的覆蓋版本,你應該刪除第二個devise_for。另外,在第一個devise_for,我認爲你可以刪除post行,因爲這是你將得到的默認值反正

一旦你做到了這一點,你就會有一組色器件的航線,以及您的其他用戶路徑(從resources :users)但是,你仍然有一個問題,你仍然有:。

user_registration POST /users(.:format) users/registrations#create 

devise_for和:

    POST /users(.:format) users#create 
因爲 resources :users

。相同的http方法和路徑被映射到不同的控制器,這是不會工作的。我建議你給用戶控制器一個不同的路徑,以保持註冊和登錄等工作(設計)和你的用戶管理控制器之間的清晰分離。相反的:

resources :users,:roles,:news ,:invites, :clubs, :events, :albums, :pictures, :static_pages, :sponsors 

試試這個:你想要的,而不是useradmin

resources :users, :path => 'useradmin' 
resources :roles, :news, :invites, :clubs, :events, :albums, :pictures, :static_pages, :sponsors 

或任何合適的路徑。這隻會改變路徑;它會保持路線助手和預期的控制器名稱相同,所以你應該有:

  new_user GET /useradmin/new(.:format)      users#new 
      edit_user GET /useradmin/:id/edit(.:format)     users#edit 
       user GET /useradmin/:id(.:format)      users#show 
        PUT /useradmin/:id(.:format)      users#update 
        DELETE /useradmin/:id(.:format)      users#destroy 

或者你可以做相反的事情;讓用戶控制器保持在/ users並將設備控制器映射到另一條路徑,使用:path => 'whatever-you-want'作爲devise_for的參數。

一旦你有這樣一個乾淨的部門,希望你的錯誤將消失!

更新

我看到有仍然路徑(在你的rake routes輸出初始users POST /users(.:format) users/registrations#create有些重疊,儘管這是POST而不是PUT,所以不似乎像它應該是一個問題PUT(除非你在不同的上下文中使用關聯的users_path幫助器),相反,它將與後面的映射到POST /users(.:format) users#create相沖突,這是因爲devise_for中的post '/users', :to => 'users/registrations#create'。額外映射?它相當於user_registration POST /club_users(.:format) users/registrations#create,只是/users ins te的/club_users。你能刪除它,所以沒有路徑重疊?我擔心它會產生影響,儘管我猜測了一下沒有控制器/視圖代碼。

順便說一句,我也使用webrick在開發。和產品中的乘客,以及Rails 3.2.17,設計等。,儘管我使用的是Ruby 1.9.3。我沒有看到明顯的原因,他們爲什麼應該成爲你自己問題的原因。這更可能是路由設置。

+0

嗨蒂姆,抱歉,遲到的回覆今天只有這個時間。所以我採取了你的意見,並調整我的路線文件。我仍然有同樣的問題。我用我當前的設置更新了我原來的帖子。 – JBOnThePc

+0

沒問題。這很奇怪。更新了答案。 – Tim

相關問題