So build yourself a resource_path helper method that calls "to_params"  
on the model of the object passed through, as Rails works.

Then you can just pass :id in through the route, because of the  
following being standard ruby:

"23-yeah-that's-great".to_i # => 23

You could even build yourself a map_resources routes helper that built  
the resource for you, so that if you decided to change how you build  
your "resource urls" sometime in the future, you'd be in the same spot  
as if you were doing it in rails (only nicer in that you'd have  
control).

If you ask me, binding resource information to the model is idiotic,  
as the model is NOT the resource, it's a sub-set of it.
But hey, we work with what we've got ;-)

Julian.

On 16/11/2008, at 2:29 PM, tommy wrote:

>
> Hi Julian,
> Thanks for the response.
>
> The problem with the proposed solution is that i have to define
> separate routes for EACH resource and replace the url method with this
> custom one[url(:location, location, location.name)]
>
> I think the Rails solution does encourage code simplicity/modularity
> because you can just set your routes to be map.resources locations and
> your link method is always the same: location_path(location). Anytime
> you need to alter the resource path, you can alter the model's to
> param method.
>
> So one method change solves the issue in Rails whereas the Merb
> implementation, i would have to search and replace all instances of
> the url method and add custom routes for each resource?
>
> Please correct me if I'm wrong here.
>
> On Nov 14, 5:05 pm, Julian Leviston <[EMAIL PROTECTED]> wrote:
>> That seems like a spastic place to put it, to me.
>>
>> What if you want to re-use your models at a later date? If so, you've
>> got some kind of URL-bindings in them... what if the models aren't
>> even being used in a merb or rails app?
>>
>> Way to tie the models to the app forever!
>>
>> This is the problem with Rails - it doesn't focus on re-use enough.  
>> If
>> I remember correctly DHH even said something akin to you're better  
>> off
>> rolling a fresh project each time from memory.
>>
>> Me? I'd prefer drop-in-reusable code.
>>
>> This push towards tiny controllers is a bit stupid, IMHO. The
>> controllers essentially are the core glue of your app. The view layer
>> is the part where the user interfaces with your app, and this (as far
>> as I'm concerned) includes the URL - this is a part of the user-
>> interface to your app. Thus, the router is part of the view layer.
>>
>> Therefore,  the router should be the place to specify this. The
>> documentation is a little light on, isn't it?
>>
>> So far as I can see, the way to do this would be a named route  
>> thusly:
>>
>> # in your routes file
>>
>> Merb::Router.prepare do
>>         match("/location/:id-:name").to(:controller  
>> => :location, :action
>> => :show).name("location")
>> end
>>
>> # usage - in view files
>>
>> url(:location, location, location.name)
>>
>> It would be nice to be able to specify methods of arguments:
>>
>> Merb::Router.prepare do
>>         match("/location/:id- 
>> #{argument_1.id.as(:id)}").to(:controller
>> => :location, :action => :show).name("location")
>> end
>>
>> but that looks really messy and convoluted. There must be a simpler
>> solution: I'd wager it'd be off the beaten-track of rails-like  
>> routes.
>> Surely we've outgrown them in flexibility and function. Shit, I know
>> Rails has!
>>
>> Essentially what would we're aiming at is a good way to specify
>> matching 'location/' then a named (:id) parameter that represents the
>> first object's id method, then a named parameter (:name) that
>> represents the first object's name method.
>>
>> Food for though.
>>
>> Julian.
>>
>> On 15/11/2008, at 11:33 AM, [EMAIL PROTECTED] wrote:
>>
>>
>>
>>> hi,
>>> how can i define the routes such that url(:location, location) would
>>> generate this url "/location/3-san_diego"  rather than "/location/3"
>>
>>> I don't understand this help page
>>> http://wiki.merbivore.com/howto/router
>>
>>> In Rails, I can define the url in the model, not the routes file  
>>> using
>>> defto_param"#{id}-#{name}" end
>>
>>> O Nov 13, 11:40 am, "Michael Klishin" <[EMAIL PROTECTED]>
>>> wrote:
>>>> 2008/11/13 [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
>>
>>>>> Won't the router just catch urls, not define them?
>>
>>>> Router defines rules for both recognition and generation. Same  
>>>> thing
>>>> in Django, Rails, Pylons and wherever else you can find the same
>>>> routing table approach.
>>>> --
>>>> MK
>>
>>
> >


--~--~---------~--~----~------------~-------~--~----~
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