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 1089401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:12:59+00:00 2026-05-16T23:12:59+00:00

New to rails and I have what I think is a basic question. In

  • 0

New to rails and I have what I think is a basic question.

In an admin view, there will be varying operations done on different data models. I have a layout “admin” which has various tabs the user clicks to load forms to edit various sets of data.

Should the controller for everything that can be edited in this view be in admin_controller (ie, have an edit_product, edit_user…), or is it better to leave the functions in the controller for each model (say users_controller, products_controller, orders_controller) and specify in the controllers to use the admin layout?

I’m working through my first rails project, and it seems either way works, but obviously I want to follow the right convention going forward so any hint, or a link to an article about this topic would be appreciated.

Thanks,

  • 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-16T23:13:00+00:00Added an answer on May 16, 2026 at 11:13 pm

    The proper Rails way to do this would be to use Namespaces. I’ll give an example below:

    Inside your controllers folder, you add a new folder called admin, and for each model you want to edit as an admin, add a controller. Here is a basic blog application:

    app/
      models/
      views/
      controllers/
        users_controller.rb
        posts_controller.rb
        comments_controller.rb
        admin/
          users_controller.rb
          posts_controller.rb
          comments_controller.rb
    

    Notice the new folder layer within our controller folder. Inside each of these files, you’ll change the definition of the class, from:

    class UsersController < ApplicationController
    

    to:

    class Admin::UsersController < ApplicationController
    

    Now, within your congif/routes.rb file, you can namespace your routes to the admin namespace, like so:

    map.namespace :admin do |admin|
      admin.resources :users
      admin.resources :posts
      admin.resources :comments
    end
    

    Now, you can go to a URL such as: http://localhost:3000/admin/users/1 and you’ll have access to whatever you specified in the admin version of your users controller.

    You can read more in this StackOverflow question, and read up on the Routes here.

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

Sidebar

Related Questions

First of all, let me say I am very new to rails, have been
I am new to Ruby on Rails, I have completed the Blog Tutorial .
I am working on the admin section of a new rails app and i'm
I have Rails app, and every once in a while, when I bring new
I realize that this is probably a very basic question, but I have spent
I'm new to rails and I can think of several ways to solve this
Relatively new to rails and trying to model a very simple family tree with
I'm new to Rails development, and I'm trying to figure out how to use
I am fairly new to Rails and I was curious as to some of
I'm kinda new to using Rails, and an app I am working on is

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.