ruby on rails - How to set up routes / link like this? -


Take a look at

If you click on $ 3,000 and take a look at the URL Maybe:

"3000-under"

Assume how you are using it, how will it be done in the streets?

Quick reference search by default search argument [: Parameters] suggests that there is a map for a model area. For example, the case of Haystack: {: search => {: price_less_than => '3000'}}

What I'm stopping is how they / los-angeles / 3000-under But once I see the route, I can understand it more.

The next question, which route is currently active, is the best way to present it in a way

For example, if you "someone Also click on "Budget" and redirect, it says "any budget", and if you click "3000 and below", it will redirect and then say "3000 and below". I am assuming that they are matching against the URL and displaying appropriate text inline with it?

Be sure to see routes / controllers, but it seems that some default routing abuses

You might note while writing in the URL which is not indicated in the budget drop down, actually does not reduce the results, I do not think it is using any complex search logic That's my guess, this is just the name of the scope.

Route:

  map.connect ': location /: terms',: admin = & gt; "Companies",: Action => "For_location" map.connect ': terms',: admin = & gt; "Companies",: Action => "For_budget"  

Then the controller of companies is probably set something like this:

  def for_location @ location = location.find_b_name (params [: location ]) @companies = Case Param [[post] [3000 / -] Under 3000-30000 | 10000-to-25000. 25000-to-50000. 50000-up / @ location.companies.send (params [: conditions]) Other @ location.companies for the end RF def_budget @companies = case parameter [: terms] when under 3,000. 3000 to 10000 10000-to-25000. 25000-to-50000. 50000-Up / Companies. Send (Parameters [: Conditions]) Other @ Companiones = Companies. All End Closing  

Named scope are defined as follows:

  Class company & lt; ActiveRecord :: Base ... Named_Space: Under 3000-Under: Terms => "Budget & lt; = 3000" named_scope: 3000-to-10000 ,: conditions = & gt; "Budget & gt; = 3000 and budget" = 10000 "named_scope: 3000-to-10000 ,: conditions = & gt; "Budget> = 10000 and budget" lt; = 25000 "named_scope: 3000-to-10000 ,: conditions = & gt; "Budget & gt; = 25000 and budget" $ 50000 "named_scope: 3000-to-10000 ,: conditions = & gt; Edit "Budget & gt; = 50000" end  

Because: Creating this dynamic is an interesting problem ...

You can make a complete search dynamic only Small bit more effort

Route:

  map.connect ': location /: term1-: term2',: admin = & gt; "Companies",: Action => "For_location" ,: term1 = & gt; / \ D + | Under | Up /,: term2 = & gt; / \ D + / map.connect ': term1-: term2',: admin = & gt; "Companies",: Action => "For_budget" ,: word1 = & gt; / \ D + | Under | Up /,: term2 = & gt; / \ D + /  

Controller:

  def for_location @ location = location.find_b_name (param [[location]) @companies = @ location.companies . Send ("search_ # {params [: term1]} _ # {params [: term2]}") end def for_budget @companies = companies. Send ("search_ # {params [: term1]} _ # {params [ : Term2]} "end  

model:

  def self.method_missing (method, * args) if method.match (/ ^ search_ (above) | | \ D +) _ (\ d +) $ /) first_term, second_term = $ 1, $ 2 if first_term == "under" self.find (: conditions = & gt; ["value & lt; =?" , Second_term]) Elsf first_term = = "up": self.find (: conditions => ["price> gt =?", Second_term]) else self.find (: conditions => ["value & Gt; =? And the price & lt; =? ", * [First_artarm, seconds_torm] .SOURT) and end (method, * AGR) end and  

: Matches the place / 300-400 or /: of the baton. Location / bottom -5000 or above -27 will use dynamic finder.

Super Double Bonus: These dynamic searches can be chained with associations and designated scopes.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -