/clients/1/trips/1/elements <- this should be a named_resource

then you can use the url() helper

Example:

I have in my router.rb

match("/referrers/:id/covernotes/:covernote_id/edit(.:format)", :method =>
[:get]      ).to(:controller => "referrers_covernotes", :action => "edit"
).name("referrer_edit_covernote")

Then I can use the url helper to sub in the params

%a.one{:href => url(:referrer_edit_covernote, @active_referrer.id,
@covernote["_id"])} Edit

I got stuck using nested resources so went verbatim and specified all my
routes by hand.
This took a little bit more effort however the exercise allowed me to "get"
how the router works and how I can use it when I need to away from the
"merb-gen resource"

Nick :)


On Mon, Oct 26, 2009 at 10:50 PM, George Adamson <
[email protected]> wrote:

>
> When using nested resource URLs like this:
> http://localhost:4000/clients/1/trips/1/elements
>
> to make a link like that I use: <%= link_to "Cancel", resource
> ( @client, @trip, :elements ) %>
> (Explicitly specifying the client and trip to build the url)
>
> This means every action in the controllers has to derive @client and
> @trip like this if I want to generate links in the view:
>
>    @trip = Trip.get( params[:trip_id] )
>    @client = Client.get( params[:client_id] )
>
> This seems like a lot of repeated code. Is there a simpler, shorter
> (more automated) way to generate resource URLs?
>
> For example, just use <%= link_to "Cancel", resource( :elements ) %>
> and it figures out the url "context" by itself?
>
> Is this a job for a helper method? Named routes? Other?
>
> Cheers,
>
> George
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"merb" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/merb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to