我在哪里初始化常量?我以为它只是在控制器中。
错误
uninitialized constant UsersController::User
用户控制器
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
end
def new
end
end
路线
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'
用户.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
这可能有助于我也得到
The action 'index' could not be found for UsersController
当我转到用户页面时,但是当我转到 users/1 时,出现上述错误。