Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 912545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:24:01+00:00 2026-05-15T17:24:01+00:00

I’m working on an application with quite a few related models and would like

  • 0

I’m working on an application with quite a few related models and would like to hear some opinions on how best to organize the controllers.

Here are some options I have been considering:

1) Namespace the controllers. So, for example, have a controllers/admin directory and a controllers/public directory. This seems appealing for organization but also sorta contrived since a single resource could often have actions which might sensibly belong in different directories (e.g. the show action is public whereas the create action is admin). So this would mean breaking up some of my resources into two separate controllers – one public, one admin. Seems bad.

2) Create nested resources. I’ve only occasionally used nested resources so it’s not always clear to me when it’s best to nest resources versus simply passing the data you need through the params explicitly. Does anyone has some suggestions/examples of how best to use nested resources? When is it a good idea? When is it an overkill?

3) Just leave the default scaffolded controllers alone. Create new collection/member actions where needed and use before filters to set permissions within each controller. This seems most appealing since it keeps things simple upfront. But I’m sorta nervous about things getting messy down the line as some of the controllers might start to bloat with several new actions.

If anyone with experience designing large applications could offer some guidance here, it’d greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T17:24:02+00:00Added an answer on May 15, 2026 at 5:24 pm

    For organizing within our applications, I have done a little bit of everything depending on the situation.

    First, regarding the separate controllers for admin/user functions, I will say that you probably don’t want to go that route. We used authorization and before_filter to manage rights within the application. We rolled our own, but 20/20 hind-sight, we should have use CanCan. From there you can setup something like this (this is pseudo-code, actual language would depend on how you implemented authorization):

    before_filter :can_edit_user, :only => [:new, :create, :edit, :update] #or :except => [:index, :show]
    
    protected
    
    def can_edit_user
      redirect_to never_never_land_path unless current_user.has_rights?('edit_user')
    end
    

    Or at a higher level

    before_filter :require_admin, :only [:new, :create]
    

    and in your application controller

    def require_admin
      redirect_to never_never_land_path unless current_user.administrator?
    end
    

    It would depend which route, but I would use that for authorization instead of splitting up controllers.

    As far as name spaces vs. Nested Resources, it depends on the situation. In several of our apps, we have both. We use name spaces when there is a cause for a logical separation or there will be shared functions between a group of controllers. Case and point for us is we put administrative functions within a namespace, and within we have users, roles and other proprietary admin functions.

    map.namespace :admin do |admin|
      admin.resources :users
      admin.resources :roles
    end
    

    and then within those controllers we have a base controller, that stores our shared functions.

    class Admin::Base < ApplicationController
      before_filter :require_admin
    end
    
    class Admin::UsersController < Admin::Base
      def new
       ....
    end
    

    This provides us logical separation of data and the ability to dry up our code a bit by sharing things like the before_filter.

    We use nested controllers if there is going to be a section of code where you want some things to persist between controllers. The case from our application is our customers. We search for and load a customer and then within that customer, they have orders, tickets, locations. Within that area we have the customer loaded while we look at the different tabs.

    map.resources :customers do |customer|
      customer.resources :tickets
      customer.resources :orders
      customer.resources :locations
    end
    

    and that gives us urls:

    customers/:id
    customers/:customer_id/orders/:id
    customers/:customer_id/tickets/:id
    

    Other advantages we have experienced from this is ease of setting up menu systems and tabs. These structures lend themselves well to an organized site.

    I hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.