How can I allow users to switch between different views of the same content using a selection menu. For example look at the right hand side of http://railscasts.com/. You can switch between list view, table view and grid thumbnail view. What would be a good way to accomplish this?
Share
You could set up a partial for each view, and either use
sessionto store the preference or simply useparams.In
index.html.erb:Then you would save each view partial in the controller’s views folder, e.g.
_grid.html.erb,_list.html.erb, and_default.html.erbEDIT
In response to a comment on this (now five-year-old) answer, I am rescinding/amending my original advice. It’s never a good idea to pass unverified params to
render, because it has the potential to expose arbitrary data from your filesystem. Would instead recommend a whitelisting method:And in more direct response to the comment: