just getting a really weird error and was wondering if anyone could enlighten me as to what is going on.
First of all here is my code:
class UsersController < ApplicationController
def index
list
render("list")
end#end index
def new
@user = User.new
end#end new
def create
@user = User.new(params[开发者_JS百科:user])
if @page.save
flash[:notice] = "Page Created Successfully!"
redirect_to(:action => 'list')
else
render('new')
end#if else
end#end create
def list
@list = User.order('users.position ASC')
end#end list
def show
@user = User.find(params[:id])
end#end show
def edit
@user = User.find(params[:id])
end#end edit
def update
@user = User.find(params[:id])
if @user.update_attributes(params[:page])
flash[:notice] = "Page updated Successfully"
redirect_to(:action => 'show', :id => @user.id)
else
render('edit')
end#end if else
end#end update
def delete
@user = User.find(params[:id])
end#end delete
def destroy
User.find(params[:id]).destroy
flash[:notice] = "User has been removed"
redirect_to(:action => 'list')
end#end destroy
end#end class
I am getting a type error when I run the server and go to http://localhost:3000/users/new
NameError in UsersController#new
uninitialized constant UsersController::User Rails.root: C://Documents/Programming/Ruby Files/kccoding
Application Trace | Framework Trace | Full Trace app/controllers/users_controller.rb:7:in 'new'
But I don't see myself trying to do that at all... AND I am getting no line numbers as to where this error is coming from... Any suggestions?
Kelan
EDIT ~~~ I changed the variables to User.<>, but I'm getting an "uninitialized constant UsersController::User" error. It is in whichever method I am trying to call.
I think this is your problem:
render('new')
It should be:
render :action => 'new'
Try that in your new
method.
You sure it's not User.new
that you want.
def new
@user = User.new
end#end new
Instead of Users.new you need to type:
def new
@user = User.new
end#end new
Check for proper model name everywhere in controller (Users => User)
It seems error doesn't just come from controller code. Do post you error trace from log files, something can be found from that only.
精彩评论