Should frontend and backend handled by different controllers?

Posted by DR on Stack Overflow See other posts from Stack Overflow or by DR
Published on 2010-05-01T13:06:36Z Indexed on 2010/05/01 13:27 UTC
Read the original article Hit count: 301

In my previous learning projects I always used a single controller, but know I wonder if that is good practice or even always possible.

In all RESTful Rails tutorials the controllers have a show, an edit and an index view. If an authorized user is logged on, the edit view becomes available and the index view shows additional data manipulation controls, like a delete button or a link to the edit view.

Now I have a Rails application which falls exactly into this pattern, but the index view is not reusable:

  1. The normal user sees a flashy index page with lots of pictures, complex layout, no Javascript requirement, ...
  2. The Admin user index has a completly different minimalistic design, jQuery table and lots of additional data, ...

Now I'm not sure how to handle this case. I can think of the following:

  1. Single controller, single view: The view is split into two large blocks/partials using an if statement.
  2. Single controller, two views: index and index_admin.
  3. Two different controllers: BookController and BookAdminController

None of this solutions seems perfect, but for now I'm inclined to use the 3rd option.

What's the preferred way to do this?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about architecture