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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:01:29+00:00 2026-06-05T02:01:29+00:00

Where do I initialize the constant? I thought it was just in the controller.

  • 0

Where do I initialize the constant? I thought it was just in the controller.

Error

uninitialized constant UsersController::User

Users Controller

 class UsersController < ApplicationController
      def show
        @user = User.find(params[:id])
      end
      def new
      end
    end

routes

SampleApp::Application.routes.draw do

  get "users/new"
 resources :users
  root to: 'static_pages#home'

  match '/signup', to: 'users#new'

  match '/help', to: 'static_pages#help'
  match '/about', to: 'static_pages#about'
  match '/contact', to: 'static_pages#contact'

user.rb

 class AdminUser < ActiveRecord::Base
      attr_accessible :name, :email, :password, :password_confirmation
      has_secure_password
      before_save { |user| user.email = email.downcase }
      validates :name, presence: true, length: { maximum: 50 }
      VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
      validates :email, presence: true,
      format: { with: VALID_EMAIL_REGEX },
      uniqueness: { case_sensitive: false }
      validates :password, presence: true, length: { minimum: 6 }
      validates :password_confirmation, presence: true
    end

This might help
I am also getting

The action 'index' could not be found for UsersController

when I go to the users page, but when I go to users/1 I get the above error.

  • 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-05T02:01:31+00:00Added an answer on June 5, 2026 at 2:01 am

    You have a couple of problems here –

    1. Your AdminUser model should be called User, as it’s defined in user.rb, and your UsersController is trying to find them, which is why you get the uninitialized constant UsersController::User error. The controller will not define the User class for you.

    2. You haven’t defined an index action in UsersController, but you’ve defined a route for it. When you declare a resource in your routes.rb file, Rails will create 7 routes by default, which point to specific actions in the controller – index, show, new, edit, create, update, and delete. You can prevent Rails from defining one or more of the routes, via the :only parameter – e.g. resources :users, :only => [:new, :show] You can see the routes that are defined, as well as the controller actions they will call with rake routes. http://localhost:3000/users will hit the UsersController#index action by default, while http://localhost:3000/users/1 will hit the UsersController#show action by default, passing 1 as the id param.

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

Sidebar

Related Questions

Just like in C++ is it possible to initialize class constant in the constructor?
class Observer def initialize(&block) instance_eval(&block) if block_given? end end I'm wondering what assumption is
I want to initialize constant in child-class, instead of base class. And use it
I'm getting uninitialized constant Date (NameError) with the following code: class Test attr_accessor :reqs
What I just want is to initialize a string[] array constant by specifying not
here is my controller: class AdminController < ApplicationController before_filter :require_user authorize_resource :class => false
Right now I have: module A class B def initialize @y = 'foo' end
Is it possible to initialize a static constant member in a class definition? Please
When initialize an entity framework context. One is to initialize at class level, such
def initialize(apps, catch=404) @apps = []; @has_app = {} apps.each { |app| add app

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.