开发者

Mixed dynamic routes in Rails/Merb

Im trying to figure out the best way to map simple routes into one url. Application contains of 4 models: Location, Category, Budget, Company. But each model could be mapped to single url like this. For real-world example you can check out http://sortfolio.com/

/chicago <- Location
/3k-5k <- Budget
/bars <- Category
/company-name <- Company

And also they can be mixed into something like this:

/chicago/3k-5k <- Location, Budget
/chicago/bars/3k-5k <- Location, Category, Budget
/bars/3k-5k <- Category, Budget
/foo-bar <- Company

So, basically there is a specific order of parameters:

Location/Category/Budget

There are 2 routes to match all of the url`s:

match('/').to(:controller => 'search', :action => 'index')
match('/:location(/:category(/:budget)))').to(:controller => 'search', :a开发者_如何学Cction => 'index')

But in controller it gets a little tricky, because i have to check for items in specific order. Company url goes last because they might override the system paths.

Its working fine, but i have to make a lot of lookups per request because parameters are totally dynamic. Not a big deal, such info could be stored in cache, but im just wondering if there are any other solutions or approaches?

I have just one on my mind: having 1 additional table to store information about path and where it leads. In other words - table denormalization.

+----+----------+------------+
| ID | Url      | ObjectType |
+----+----------+------------+
| 1  | chicago  | location   |
| 2  | bars     | category   |
| 3  | 3k-5k    | budget     |
| 4  | foo-bar  | company    |
+----+----------+------------+

And url parsing process might be packed just in one custom query.

Please advice.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜