Rails web application control panel with ajax tabs

2020-08-05 09:51发布

问题:

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?

回答1:

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: Rails Sub-controllers?



回答2:

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)