We're building a custom cms and I was wondering if it's possible to have everything go through one route but to conditionally show a different view. So for example, everything is an asset but the sub-type could be article, or video, etc. Would it be possible to conditionally map to an article view?
Asked
Active
Viewed 158 times
1
-
I think you are looking for :as, see here http://stackoverflow.com/questions/4503550/route-alias-in-rails – Candide Nov 10 '11 at 21:08
-
Thanks for the response, although in our case I don't think we could make it as simple as that since it would be conditional on an attribute of the object. So an asset with a content_type of "video" would go one way, "image" would go somewhere else. – Micharch54 Nov 10 '11 at 23:08
2 Answers
2
You can render whatever you want. (Nutshell version.)
It sort of sounds like some sort of class inheritance should have been used, though, and each should have their own controller/templates.

Dave Newton
- 158,873
- 26
- 254
- 302
-
I would agree with you, my stance on it is that we should just have our articles etc, inherit from the asset but I don't have any say on system architecture, only on how and if we can do something. If that makes sense. – Micharch54 Nov 10 '11 at 23:10
-
1It doesn't. If you're developing code on the system, you need the authority to change anything that gets in your way, including the architecture. – Marnen Laibow-Koser Nov 16 '11 at 02:55
0
This is not really a good idea, if I understand correctly. Sounds like you're trying to reinvent Rails' routing system. Instead of reinventing it, use it!
If I misunderstand, please explain your use case in more detail.

Marnen Laibow-Koser
- 5,959
- 1
- 28
- 33
-
I was asking because our team lead was wondering about routing with this method. We're essentially having a front-end rendering system that de-normalizes the data into very few tables. It's still in the planning process but we were wondering if this was even possible. – Micharch54 Nov 10 '11 at 23:06
-
It's possible but a little pointless. Spend the effort learning to work *with* Rails' routing, not *against* it. Also, why the denormalization? Sounds smelly... – Marnen Laibow-Koser Nov 11 '11 at 00:40