문제

how can I generate a RoR route like this one:

Prefix: gateway

verb: post

URI Pattern: /region/:id/gateway

Controller#Action: region#gateway

I tried with

resources :region, :only => :show do
    post :gateway, :only => :show
end

but is generating by default a route to show the regions

/region/:id(.:format)

I want to skip the regions show action and only keep it the /region/:id/gateway route

도움이 되었습니까?

해결책

post "gateway/region/:id/gateway" => "region#gateway"

다른 팁

Have a look to Rails routing documentation. It's well documented.

If You want to use resources, You may write:

resources :region do
 member do
    post :gateway
 end
end

It will be recognized as:

region/:id/gateway

You can't use "only" because it reduce to one action!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top