Rails 3 路由寻找错误的控制器
首先,我在 config/route.rb 中有这条路
get 'inbox/index' => 'inbox#index'
由然后我运行了 rake paths,路由被正确生成:
inbox_index GET /inbox/index(.:format) {:action=>"index", :controller=>"inbox"}
问题是当我尝试从浏览器获取页面时(http://localhost:3000 /inbox/index),出现错误消息:
ArgumentError in InboxesController#index
wrong number of arguments (2 for 0)
应用程序跟踪中没有任何内容,并且在环境转储中生成了正确的控制器:
action_controller.instance: #<InboxController:0x7fbde79fb5a8 ...
为什么rails 尝试调用 InboxesController
?
顺便说一句,我在同一个应用程序中有另一条路线可以完美地工作:
match "search" => 'search#search', :as => 'search', :via => [:get, :post]
我不知道如何隔离这个问题,请给我一个提示。
First I had this route in config/route.rb
get 'inbox/index' => 'inbox#index'
Then I ran rake routes
, the route was correctly generated:
inbox_index GET /inbox/index(.:format) {:action=>"index", :controller=>"inbox"}
Problem is when I tried to get the page from the browser (http://localhost:3000/inbox/index), there's an error message:
ArgumentError in InboxesController#index
wrong number of arguments (2 for 0)
There is nothing in the application trace, and the right controller is generated in the env dump:
action_controller.instance: #<InboxController:0x7fbde79fb5a8 ...
Why rails tried to call InboxesController
?
By the way, I have another route in the same application which works perfectly:
match "search" => 'search#search', :as => 'search', :via => [:get, :post]
I don't know how to isolate this problem, please give me a hint.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后我知道发生了什么事。
我定义了一个方法
InboxController#send
,Rails 引入的元编程已被破坏。该错误消息与情况完全无关。
Finally I found out what happened.
I defined a method
InboxController#send
, and the metaprogramming introduced by Rails had been broken.The error message is totally irrelevant to the situation.