Michel
Michel

Reputation: 3

Rails url_for with nested resource id instead of object

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.

Upvotes: 0

Views: 1595

Answers (1)

tjwallace
tjwallace

Reputation: 5688

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

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

Upvotes: 2

Related Questions