I'm using the mobile fu gem to do some user-agent detection, so that I can serve either .html or .mobile extension templates depending on the client,
Now, this part works really good, but I don't like that view folders become a bit cluttered with twice the files, ie.
app/views/profiles/show.mobile.haml
app/views/profiles/show.html.haml
app/views/profiles/edit.mobile.haml
app/views/profiles/edit.html.haml
etc, etc
what I'd like to have instead is:
app/views/profiles/html/show.html.haml
app/views/profiles/html/edit.html.haml
And
app/views/profiles/mobile/show.mobile.haml
app/views/profiles/mobile/edit.mobile.haml
And have Rails automatically look into the correct folder/directory for files depending on the Request. Is this possible to do?
Maybe this is something really easy to do, let me know if this is a behavior that comes out of the box..
Thank you
Rails 4.1 has a new built-in feature called ActionPack Variants, which detects the user-agent (like the mobile fu gem).
Basically, you can add this for example in your ApplicationController:
Let's say you have a ProfilesController. Now you can do this:
Back to your question: If you want to look for files in a different folder/directory, you can do this:
There is also a good tutorial which shows how to use it.