为什么路由要求我显示动作?

Why route asks me show action?

我转发用户到下一个URL:

http://bookworm.az:3000/messages/alizade

在我做的路线中:

get '/messages' => 'messages#index'
get '/messages/:username' => 'messages#index'

但是它要求我显示动作。但我只想显示相同的 /messages 页面。

例如,这里有效并且没有询问我有关显示操作的信息:

get ':username/manage' => 'profiles#index'

如何return同一页面不显示动作?

问题是顺序。

您已经有一条如此多的路线。类似于:资源:消息。

要工作,移动行:

get: '/messages/:username' => 'messages#index'

到 routes.rb 文件的顶部。

注释来自 Rails 指南:

"Rails routes are matched in the order they are specified, so if you have a resources :photos above a get 'photos/poll' the show action's route for the resources line will be matched before the get line. To fix this, move the get line above the resources line so that it is matched first."

http://guides.rubyonrails.org/routing.html