开发者

Rails url_for with nested resource id instead of object

开发者 https://www.devze.com 2023-02-26 06:44 出处:网络
I need to build a url inside a 开发者_高级运维controller for a nested resource: http://0.0.0.0:3000/account/1/address/new

I need to build a url inside a 开发者_高级运维controller for a nested resource:

http://0.0.0.0:3000/account/1/address/new

I could do: new_account_address_path(@account) but I'm inside the controller that has the account id on the context (params[:id]) I don't want to load the object from the db just to build the url.

What would be the best way to extend the rails helpers to to this: new_account_address_path(params[:id]) and have the http://0.0.0.0:3000/account/1/address/new ?

I also dont want to create a dummy instance.


You should be able to pass the route arguments as a hash:

new_account_address_path(:account_id => params[:account_id])
0

精彩评论

暂无评论...
验证码 换一张
取 消