Find_by_somefield() in routes?


#1

I would want to set up a route that look something like this:

map.connect “:mls”, :controller => “property”, :action => “detail”, :id
=> Property.find_by_mls(:mls).id.to_s

Is this possible? I don’t know how to pick up the params passed to a
page at this early stage of the request life-cycle.

/M


#2

map.connect “:mls”, :controller => “property”, :action => “detail”, :id
=> Property.find_by_mls(:mls).id.to_s

Is this possible? I don’t know how to pick up the params passed to a
page at this early stage of the request life-cycle.

Why do you need to do that here? Why not just:

map.connect “:mls” :controller => “property”, :action => “detail”

and then :

class PropertyController < …

def detail
unless params[:mls].blank? then
@property = Property.find_by_mls(:mls)
end
if @property.nil? then
# find the property using some other method…
end
end

end

I’m assuming of course that the goal is to get the property object with
the given MLS string…