views:

762

answers:

2

I'm looking to build a rails web app with an admin control panel. I'd like the control panel to use a tabbed interface for controlling users, projects, tasks etc, and I'd like to switch between tabs using jquery tab UI controls with ajax. Also using restful authentication for users and my own code for projects, tasks etc.

Here's what I can't wrap my head around. Normally, I'd have a controller for each tab, so validation is simple, if there's an error (say in the user) i just render the proper action with the object and it's errors and we're set. However, if I'm not refreshing (to different controllers between tabs) how does this work? Do I need to have one massive controller with all the user, project, task validation and controls (ie. crud operations)? Seems like not the greatest design.

Or is there some way I can use an 'admin' controller that encompasses separate controllers for proper crud/error checking etc.

Hope this makes sense?

A: 

I would personally use inline validation in the forms. Jquery does that pretty well , but there are a lot of library that can help you with that.

I guess it's not exactly what you were looking for, but it would make your job easier. Of course still keep validation in the models so that no one can bypass the validation (using firebug or something like this)

marcgg
+1  A: 

I would make the contents of each tab be called in by a separate ajax request. This would give you the following benefits

  • Now each tab can easily be a different view/controller
  • You only need to load the contents for a tab when it is used; you won't be processing code/downloading html for tabs that the user doesn't use.

If you don't want to use this route, (i.e. you feel you need to load all the contents of the tabs on page download in a single request) then you could separate out the code using helper methods and partials. See my answer here: http://stackoverflow.com/questions/704687/rails-sub-controllers/705781#705781

DanSingerman
So lets complicate this. My actual program uses modal div popups for adding a new user. Say I have an admin/index action. Then I load each tab with ajax from different controllers actions (users/index, projects/index etc) An 'add user' link brings up a modal div to add new user (/users/new). If there is an error saving a new user, in the controller I want render :action => 'new' with the user object that has the errors, but, I'm in the users controller.
brad
So I want the admin/index#users section, with that modal div popup displaying the user and errors. From the users controller though, I can't render an action on the admin controller. Does this make sense? I don't know how to get back to that state of creating a user, with the necessary errors
brad
To clear this up, I don't ever really want to leave the admin controller, I just want to delegate all the crud operations on it's sections off to their own controllers, but i don't ever want to display the controllers directly, i just want my admin controller to do all that. I can't figure out how to validate though without actually leaving the admin controller
brad