undefined method `screen_name' for #<User:0x13027a3>

Hi

Could anybody help me resolve this error?, i have copy n pasted my
controler and activerecord below as well.....Here is the error medssage

NoMethodError in Register_user#index
Showing app/views/register_user/index.html.erb where line #4 raised:

undefined method `screen_name' for #<User:0x13027a3>

Extracted source (around line #4):

1: <h1>Users</h1>
2: <ol>
3: <% @users.each do |user| %>
4: <li><%= user.screen_name %></li>
5: <% end %>
6: </ol>

Hi

Could anybody help me resolve this error?, i have copy n pasted my
controler and activerecord below as well.....Here is the error medssage

NoMethodError in Register_user#index
Showing app/views/register_user/index.html.erb where line #4 raised:

undefined method `screen_name' for #<User:0x13027a3>

Note the class name here, User.

Extracted source (around line #4):

1: <h1>Users</h1>
2: <ol>
3: <% @users.each do |user| %>
4: <li><%= user.screen_name %></li>
5: <% end %>
6: </ol>

-----------------------------------------------------

CONTROLLER

class RegisterUserController < ApplicationController
def register
@title = "Register"
if request.post?
@user = User.new(params[:user])
if @user.save
flash[:notice] = "User with login #{@user.screen_name} created
successfully!"
redirect_to :action => :index
end
end
end

def index
@title = "Temporary View"
@users = User.find(:all)

end

def login
end

def logout
end

end
--------------------------------------

DATABASE

class CreateRegisterUsers < ActiveRecord::Migration
def self.up
create_table :register_users do |t|

This is creating a table register_users, so the class containing a
screen_name column is RegisterUser not User, unless you have
overridden this in class User.

Colin

Hi Simon,

<% @users.each do |user| %>

change as below

<% @user.each do |user| %>

because you are mentioned in controller like this - @user = User.new(params[:user])

Colin Law wrote in post #975776:

Hi

Could anybody help me resolve this error?, i have copy n pasted my
controler and activerecord below as well.....Here is the error medssage

NoMethodError in Register_user#index
Showing app/views/register_user/index.html.erb where line #4 raised:

undefined method `screen_name' for #<User:0x13027a3>

Note the class name here, User.

6: </ol>
     if @user.save
  @title = "Temporary View"

end
--------------------------------------

DATABASE

class CreateRegisterUsers < ActiveRecord::Migration
def self.up
create_table :register_users do |t|

This is creating a table register_users, so the class containing a
screen_name column is RegisterUser not User, unless you have
overridden this in class User.

Colin

Hi thanks for the response, ah,your right because i had to create the
model, view, controller as register_user instead of user(which was how
it was done from a tutorial!, I copied the code form that same tutorial)

it just that i get aload error message when i change it to RegisterUser
and a name error message when i then tried register_user as well

So i have to change user ro RegisterUser everywhere in the controller
views etc?

Ratnam Raj varasala wrote in post #975793:

because you are mentioned in controller like this - @user =
User.new(params[:user])

On Tue, Jan 18, 2011 at 11:17 PM, Ratnam Raj varasala

okay cool thanks, I'll try that two

That depends on what you are doing. You should have a model and table
that agree with each other (User and users or RegisterUser and
register_users). RegisterUsers sounds a strange name for a model and
table though. Usually a table maps to something in the real world
(such as users). If you have a table called register_users then does
each row represent a RegisterUser (whatever that is)? There need not
be a controller with the same name however, so I am guessing that
maybe the controller should be called register_users as that is what
it does. Only you know what your app is supposed to be doing though.

Colin