Tintin81
Tintin81

Reputation: 10207

How to best split a preferences view into tabs in Ruby on Rails?

In my Rails application the show and edit views of my preferences have grown to contain about 20 or so attributes.

This is not very user-friendly since the user has to scroll to see all his preference options.

So I would like to subdivide all the attributes into tabs labelled time, formatting, and general.

What is the Rails way of doing that?

What I have in mind is filtering the views with a GET variable à la http://localhost:3000/preferences?tab=general

But will I be able to redirect to that same tab again after the user hit update? How would that have to be done?

I also wonder if validation will work using this approach.

I had a look at the RailsCast about Multistep Forms already but in my case I don't need "steps" of any sort. The user should be able to select the tabs in random order.

I also don't want to use any gems. I prefer to hack something together myself.

Thanks for any ideas.

Upvotes: 0

Views: 149

Answers (2)

Dean Brundage
Dean Brundage

Reputation: 2048

In your edit view add the tab parameter value as a hidden field to the form. It will then be passed to the update action and your controller can make a redirect decision there.

Upvotes: 0

nickcen
nickcen

Reputation: 1692

You can use jquery-ui to implement the tab view so that you can design which tab to show by javascript. You can add an if statement for each validation to indicate when will that validation will be take effect.

Upvotes: 1

Related Questions