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

  • Home
  • SEARCH
  • 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 8890203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:26:49+00:00 2026-06-14T22:26:49+00:00

My model holds expenses, including user and project references.. class Expense < ActiveRecord::Base attr_accessible

  • 0

My model holds expenses, including user and project references..

class Expense < ActiveRecord::Base
     attr_accessible :amount, :expense_date, :description, :project_id, :user_id

      belongs_to :project
      belongs_to :user
end

The ExpensesController handles basic CRUD operations for the expenses.

I now am needing to build an administrators version of this same page, a new view preferably, which can include the different views of the data, by user, by project, etc, and can also edit data that the user cannot.

My question is: Do a build a second controller to handle the administrative perspective of the data, — or do I setup conditions inside of every method, to detect the originating view and form, and then conditions to redirect them back to where they belong?

If I do build a second controller, how do I properly setup the form_for so that it knows what controller to go to?

Thanks!

PS – If anyone has any books about how to properly put together a rails app, I feel like I know the pieces ant parts, but I’m getting stuck on the big picture implementation. I learned rails with Michael Hartl’s guide, prior to that I was a PHP developer.

  • 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-06-14T22:26:50+00:00Added an answer on June 14, 2026 at 10:26 pm

    IMHO, if security is a big concern for your app then using an admin namespace and separate controllers is the best way to make sure you don’t leave any gaps. It’s also just simpler and lower stress.

    I would have a directory structure like so:

    /app/controllers/application_controller.rb
    /app/controllers/admin_controller.rb - inherits from application_controller
    /app/controllers/expenses_controller.rb - non-admin, inherits from application_controller
    /app/controllers/admin/expenses_controller.rb - inherits from admin_controller
    

    Your views would be similarly separated/duplicated:

    /app/views/expenses/* - non-admin expenses views
    /app/views/admin/expenses/* - admin expenses views
    

    In application_controller you’d put the Devise methods to authenticate_user and CanCan method to check_authorization (which throws an exception if authorization is not checked at some point in the controller action). In admin_controller you have more strict filters to make sure the user is an admin. Then you can get even more fine-grained in the specific controllers and their actions.

    Of course each controller only has to define the actions it really needs and you don’t have to duplicate views. Maybe the non-admin expenses_controller has index, show, new, create, while the admin one has only edit, update, and destroy. Then in the ‘show’ view you’d still have code that add links to the ‘edit’ action if the user is an admin.

    Edit – Routes

    With the above example, your routes.rb would look something like:

    resources :expenses, :only => [:index, :show, :new, :create]
    
    namespace :admin do
      resources :expenses, :only => [:edit, :update, :destroy]
    end
    

    So you still use expenses_path() for the index and expense_path(foo) for show. A form on the admin page, however, would post to admin_expense_path(@expense).

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

Sidebar

Related Questions

In my model, I have a base object class A which holds a set
I have a model that holds user address. This model has to have first_name
model.py: class Tribes(Group): members = models.ManyToManyField(User, related_name='tribes', verbose_name=_('members')) i want to store a number
So I've created my model, a single class that holds a few different string
I have a Django model that holds to-dos with an estimate of the amount
In my project I have a model which holds basic information about model. For
I have a Model that holds a list of Countries (List) and a user
I have a wcf service in 1 project and an object model that holds
I've got a Supplier Invoice (SupplierInvoice) parent model that holds a number of orders
Model: using System.ComponentModel.DataAnnotations; using MySite.Validators; namespace MySite.Models { public class AddItem { [Required(ErrorMessage =

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.