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:

Users


2:

    3: <% @users.each do |user| %>
    4:
  1. <%= user.screen_name %>

  2. 5: <% end %>
    6:

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|

  t.column :screen_name,            :string
  t.column :e_mail, :string
  t.column :password, :string

 #t.string :screen_name
 #t.string :e_mail
 #t.string :password

  t.timestamps
end

end

def self.down
drop_table :register_users
end
end

On 18 January 2011 16:59, Simon M. [email protected] wrote:

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:
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 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])

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

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

On 18 January 2011 18:56, Simon M. [email protected] wrote:

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

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

Colin L. wrote in post #975776:

On 18 January 2011 16:59, Simon M. [email protected] wrote:

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:
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?