Xhinking
Xhinking

Reputation: 1069

How to use a 'switch' to control Controller's Action choices in Rails?

In my new Rails project,I want to provide my user two kinds of category view mode :one is List mode,other is Detail mode.

In List mode,the category page will just show the title of the article.In Detail mode,the page will show the title and the content.I want to use a 'switch' to control this two mode,when user choice 'List mode',all the category page will be shown in List mode.When they choice 'Detail mode',all the category page will be shown in Detail mode.

I think I could use different Action control this two view mode,so my question is how to set a 'switch' to control these different Actions in the whole site? A Variable?

Also welcome another solution.

Thank you.

Upvotes: 0

Views: 197

Answers (1)

Shreyas
Shreyas

Reputation: 8757

You could use a variable and railscasts shows the way again. The new design of railscasts.com implements this sort of a design, where-in it provides an option to view articles in a list/grid fashion.

Since, railscasts is an open-source project, I encourage you to browse through the code in

  1. episodes_controller
  2. and the view episodes#index (he uses params[:view] to switch between different listing styles)

And you'll know exactly what to do.

Upvotes: 1

Related Questions