2012-04-10 78 views
3

從3.2.0升級到3.2.2時,我遇到了路由問題。從rails 3.2.0升級到3.2.2時出現「新」路由問題

當生成一個新的路線與路線幫手助手的作品,併產生一個鏈接,看起來像:

/things/new 

然而,當你訪問它拋出一個路由錯誤的鏈接...

Routing Error 
No route matches {:action=>"edit", :controller=>"app/things", :id=>#<Thing id: nil, title: n.... 

它錯誤的編輯網址操作不是一個新的。

沒有什麼的路線,但....

scope :module => :app, :as => :app, :constraints => { :subdomain => /app/ } do 
    resources :things 
    end 

有沒有人經歷過這種或知道發生了什麼?

謝謝。

額外的細節...

耙路線:

app_things GET /things(.:format)         app/things#index {:subdomain=>/app/} 
       POST /things(.:format)         app/things#create {:subdomain=>/app/} 
new_app_thing GET /things/new(.:format)        app/things#new {:subdomain=>/app/} 
edit_app_thing GET /things/:id/edit(.:format)       app/things#edit {:subdomain=>/app/} 
    app_thing GET /things/:id(.:format)        app/things#show {:subdomain=>/app/} 
       PUT /things/:id(.:format)        app/things#update {:subdomain=>/app/} 
       DELETE /things/:id(.:format)        app/things#destroy {:subdomain=>/app/} 

捲曲:

curl -IL http://app.testapp.com/things/new 
HTTP/1.1 404 Not Found 

從日誌(堆棧跟蹤):

Started GET "/things/new" for 127.0.0.1 at 2012-04-24 19:27:02 +0100 
Processing by App::ThingsController#new as HTML 
    Rendered app/things/_new_form.html.erb (2.0ms) 
    Rendered app/things/new.html.erb within layouts/app (2.7ms) 
    Rendered layouts/_app_includes.html.erb (11.0ms) 
    Rendered app/nav/_things_new.html.erb (1.6ms) 
    Rendered app/nav/_menu_wrapper.html.erb (2.1ms) 
Completed 500 Internal Server Error in 21ms 

ActionController::RoutingError (No route matches {:action=>"edit", :controller=>"app/things", :id=>#<Thing id: nil, title: nil, created_at: nil, updated_at: nil, account_id: nil>}): 
    app/views/app/nav/_step_1_title.html.erb:2:in `_app_views_app_nav__step___title_html_erb__3644446743043796555_70280275307960' 
    app/views/app/nav/_things_new.html.erb:1:in `_app_views_app_nav__things_new_html_erb__4471631226426153422_70280275315660' 
    app/views/app/nav/_menu_wrapper.html.erb:8:in `_app_views_app_nav__menu_wrapper_html_erb___3003322303253991863_70280275346820' 
    app/views/layouts/app.html.erb:32:in `_app_views_layouts_app_html_erb__4514085623626236526_70280285513740' 


    Rendered /Users/blerg/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.3/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (0.6ms) 
+1

你能發佈'耙routes'輸出? – 2012-04-15 20:18:15

+0

也希望看到堆棧跟蹤。 – TuteC 2012-04-19 03:57:11

+0

在上面增加了一些額外的細節。 – Smickie 2012-04-24 18:33:27

回答

6

我猜想這不是導致問題的/things/new路由本身。有些東西正在呈現(例如,您的_nav菜單之一),其中包含對edit_app_thing_path的調用,其中包含零或缺少對象參數。

+1

同意 - 「_step_1_title.html.erb」Smickie中有任何可疑內容? – MBHNYC 2012-04-28 14:05:55

+0

是的這是它,它是奇怪的,因爲它從未在升級之前拋出一個錯誤。而且看起來像一個也沒有被拋出的視角。乾杯! – Smickie 2012-05-22 12:40:10

4

檢查development.log文件來查看當你訪問「/東西/新」時全堆棧跟蹤。如果您無法看到日誌中出現什麼錯誤,請將其發佈到此處。

乍一看,edit_thing_path(@thing)調用中似乎存在問題:您正在傳遞新記錄 - 我在該錯誤消息中看到了#<Thing id: nil...

+0

絕對是一個問題,但它不應該以編輯路徑開始。 – 2012-04-21 16:26:28

2

在這裏工作很好。

我不知道該怎麼告訴你Smickie,我重新創建了你的情況,它對我來說工作得很好。這裏還有一些細節:

Rails的版本

$ bundle exec rails -v 
Rails 3.2.2 

的routes.rb

scope :module => :app, :as => :app, :constraints => { :subdomain => /app/ } do 
    resources :things 
end 

耙路線

$ bundle exec rake routes 
    app_things GET /things(.:format)   app/things#index {:subdomain=>/app/} 
       POST /things(.:format)   app/things#create {:subdomain=>/app/} 
new_app_thing GET /things/new(.:format)  app/things#new {:subdomain=>/app/} 
edit_app_thing GET /things/:id/edit(.:format) app/things#edit {:subdomain=>/app/} 
    app_thing GET /things/:id(.:format)  app/things#show {:subdomain=>/app/} 
       PUT /things/:id(.:format)  app/things#update {:subdomain=>/app/} 
       DELETE /things/:id(.:format)  app/things#destroy {:subdomain=>/app/} 

獲取things/new

$ curl -IL http://app.test.dev:3001/things/new 
HTTP/1.1 200 OK 
... 

如果您發佈從您的計算機相同的細節,我們會看到什麼可疑。

+0

乾杯。像你問的那樣添加了更多的細節。 – Smickie 2012-04-24 18:33:12

0

使用本:

scope "/app" do 
    resources :things 
end