Hi George,
I'm not aware that what you want would be possible in the Merb. The
"and it figures out the url "context" by itself?" is kind a magic,
isn't it? It suppose that you'll use the same variable naming all the
time for your instance variables.
What I suggest is to write helpers. You can have set of controllers
which can use the same helpers. There you can have helper like
setup_client_and_trip() or even something more generic which sets your
@client and @trip variables.
Put in application.rb or any controller you want
"before :setup_client_and_trip". And than write helper
client_trip_elements_url like this:
def client_trip_elements_url(param = {})
resource(@client,@trip,:elements, param)
end
That way you have your setup code and URL generation in one place. And
it will simplify your code.
Pavel
On Oct 26, 11:50 am, 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
-~----------~----~----~----~------~----~------~--~---