3

在将 rails 从 3.2.0 升级到 3.2.2 时,我遇到了一些路由问题。

当使用 routes 助手生成新路由时,助手工作并生成如下所示的链接:

/things/new

但是,当您访问该链接时,它会引发路由错误...

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

它将其误认为是编辑 url 操作而不是新操作。

路线上什么都没有,但是......

  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)
4

4 回答 4

6

我猜这不是/things/new导致问题的路线本身。正在渲染的内容(例如,您的 _nav 菜单之一)包括edit_app_thing_path使用 nil 或其他缺少对象参数的调用。

于 2012-04-24T18:50:05.130 回答
4

当您访问“/things/new”时,检查您的 development.log 文件以查看完整的堆栈跟踪。如果您无法从日志中看到有什么问题,请在此处发布。

乍一看,edit_thing_path(@thing)调用中似乎存在问题:您正在将新记录传递给它 - 我#<Thing id: nil...在该错误消息中看到。

于 2012-04-18T08:37:07.710 回答
2

在这里工作正常。

我不知道该告诉你什么 Smickie,我重新创建了你的情况,它对我来说效果很好。以下是一些细节:

导轨版本

$ bundle exec rails -v
Rails 3.2.2

路由.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
...

如果您从您的机器上发布相同的详细信息,我们会看到什么是可疑的。

于 2012-04-21T16:18:13.877 回答
0

用这个:

scope "/app" do
  resources :things
end
于 2012-05-01T03:01:16.423 回答