I answered a question in stackoverflow but I gave a solution that looks a little dirty to me, I'd like your opinion because I think there is a much smarter way to do it.
A guest user should be able to choose between two different view modalities.
My approach was to implement an action and store the choice in the session. I paste some relevant code here as well:
# application_controller.rb
def set_view_type # TODO: here is the part I don't like
session[:view_type] = params[:view_type]
redirect_to :back
end
# x_controller.rb
def index
case session[:view_type].to_sym
when :box render 'index_box'
else render 'index_list'
end
end
Then I use two link_to
(instead of radiobutton
as in stackoverflow) to choose the view, and those should be visible anytime in the layout, this is why I use application_controller
for that.
PS: I don't know if it's correct to ask for a question that it's still open in SO, feel free to answer straight there by me, I just think here I'm posting my solution that I would like to be revised.