未初始化的常量YourSpace :: UsersController :: User

时间:2015-01-17 15:23:13

标签: ruby-on-rails

错误

  uninitialized constant YourSpace::UsersController::User

控制器

 class YourSpace::UsersController < ApplicationController

def new
 @title = YourSpace
end

def edit
 @title = YourSpace
 @user = User.find(params[:id])
end

 def update
  name = params[:user][:name]

  if name.blank?
   flash[:notice] = "Name can not be blank dawg!"
   redirect_to :back
  else
   User.find(params[:id]).update_attributes(params[:user])
   # redirect_to :action 'show'
   redirect_to :action => :show
   # render :action => 'show'
 end
 end

 def index
  @title = YourSpace
  @users = User.limit(100).order('created_at DESC')
 end

 def show
  @title = YourSpace
  @user = User.find(params[:id])
 end
end

路线

Rails.application.routes.draw do


root 'site#home'
get '/about', to: 'site#about', as: :about

namespace :your_space do
 resources :users
end

namespace :word_cloud do
 resources :words, :only => [:index, :create]
end

namespace :word_clock do
 resources :page, :only => [:index]
end

namespace :wish do
 resources :page, :only => [:index]
end

end

当启动rails服务器时,我在YourSpace UsersController中收到错误,其中这行代码@users = User.limit(100).order('created_at DESC')显然全部被抬起。请知道我试图在365天内复制180个网站,这些网站主要是使用ruby和rails构建的。我紧跟着回购,以建立肌肉记忆。学习如何思考和编程非常新。

1 个答案:

答案 0 :(得分:0)

首先想到的是错误..解决问题的方法User改为::User


我首先想到的是你需要将YourSpace::UsersController放在app/controllers/your_space/users_controller.rb中。 Rails强制目录结构。