Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4018254
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:57:38+00:00 2026-05-20T09:57:38+00:00

How to create different view modes. Like a visitor can choose list or box

  • 0

How to create different view modes. Like a visitor can choose list or box view.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T09:57:39+00:00Added an answer on May 20, 2026 at 9:57 am

    It depends how much these views are similar, what I would do is to create partials for each view and then in the main view I call the right one depending on the property. Say you have a function in application_helper which_view in your index you can write something like this:

    <!-- your index -->
    <%= render which_view == :box ? 'index_box' : 'Index_list' %>
    

    I prefer the previous, but if you have few changes you can go for something like:

    <% if session[:view_type] == 'box' %>
    
      <!-- box content -->
    
    <% else %>
    
      <!-- list content -->
    
    <% end %>
    

    ** EDIT **

    make the action:

      # application_controller.rb
      def set_view_type # TODO: refactor
        session[:view_type] = params[:view_type]
        redirect_to :back
      end
    

    set your routes:

      # routes.rb
      match '/set_view_type' => 'application#set_view_type', :as => :set_view_type
    

    write your form:

      <!-- _view_type_selection.html.erb -->
      <%= form_tag set_view_type_path do %>
    
        <%= radio_button_tag :view_type, :box, session[:view_type] == 'box' %>
    
        <%= radio_button_tag :view_type, :list, session[:view_type] == 'list' %>
    
        <%= submit_tag 'select' %>
    
      <% end %>
    

    Not best practice but it works!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I create a view different from index action (for example the action video/add)
I want to create a view that has different displays according to the role
How can I create a new Exception different from the pre-made types? public class
Can c++ create array of pointers to different classes dynamically loaded from dll? ps.without
I have a MVC3 view that enables the user to create a couple different
I am connecting to an XML back-end to create different pages for a flash
I am trying to create two different sets of settings for datepicker( http://keith-wood.name/datepick.html )
I have a requirement to create two different maps in C++. The Key is
For a project I'm working on, I need to create objects using different source
There are two different ways to create an empty object in JavaScript: var objectA

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.