Forum: Ruby on Rails find_by_somefield() in routes?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
ArcticLeo (Guest)
on 2007-01-11 03:57
(Received via mailing list)
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
Philip H. (Guest)
on 2007-01-11 07:49
(Received via mailing list)
> 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...
This topic is locked and can not be replied to.