Yeah... I'm totally struggling to grok resource routes too... seems like they've totally blown the beautiful simplicity of the old url pattern stuff out of the water.
Would love to hear an answer to this question!!!
b
Andy Triboletti wrote:
Yeah... I'm totally struggling to grok resource routes too... seems like they've totally blown the beautiful simplicity of the old url pattern stuff out of the water.
Would love to hear an answer to this question!!!
b
Andy Triboletti wrote:
Found a solution and that is to override to_param on each of the
objects, so in the thing model I have
def to_param "#{uid}" end
Then in things_controller I have
def show @thing = Thing.find_by_uid(params[:id]) end
There's also a patch out at http://dev.rubyonrails.org/ticket/6814,
which allows you to use map.resources :things, :key => :uid and that
way you could just use
Thing.find(:params:uid)
in your controller.
Andy
Just to make it clear, there's nothing in the resource routes that prevent you from using an alternate field. It all has to do with what your controllers expect to find in the params[:id] parameter.