在 routes.rb
中给出以下路线:
scope '/rest/messages(/new)', module: 'rest' do
get '/moufa(/:id)', to: 'some_controller#some_action', as: :moufa
end
在rails控制台中我尝试 app.moufa_url
,然后我收到 "http://www.example.com/rest/messages/moufa"
但是,当我做 app.moufa_url(id: 7)
时,我收到 "http://www.example.com/rest/messages/new/moufa/7"
我尝试了几个路由,看起来每当有人请求带参数的路由的url时,返回的url包含 /new
可选部分,但是当没有提供参数时,它被省略 .
我进入了ActionDispatch的代码,从那里到Journey,找出为什么会发生这种情况 . 可悲的是,Journey的概要警告我,它变得非常复杂,我放弃了牦牛剃须 .
Any ideas why the url helpers are behaving like this? Is it possible to force them to omit the optional segment?
版本:Rails v3.2.17,Ruby v1.9.3