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> ----------------------------------------------------- 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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 18 January 2011 16:59, Simon M. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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.> > > > 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> > 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-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ratnam Raj varasala
2011-Jan-18 17:47 UTC
Re: undefined method `screen_name'' for #<User:0x13027a3>
Hi Simon, <% @users.each do |user| %> change as below <% @user.each do |user| %> On Tue, Jan 18, 2011 at 10:29 PM, Simon M. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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> > > > > 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| > > 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 > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ratnam Raj varasala
2011-Jan-18 17:48 UTC
Re: undefined method `screen_name'' for #<User:0x13027a3>
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 <chinnujune-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> Hi Simon, > > <% @users.each do |user| %> > > change as below > > <% @user.each do |user| %> > > > On Tue, Jan 18, 2011 at 10:29 PM, Simon M. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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> >> >> >> >> 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| >> >> 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 >> >> -- >> Posted via http://www.ruby-forum.com/. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> >> . >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law wrote in post #975776:> On 18 January 2011 16:59, Simon M. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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: </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. > > ColinHi 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? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 varasalaokay cool thanks, I''ll try that two -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2011-Jan-18 20:47 UTC
Re: Re: undefined method `screen_name'' for #<User:0x13027a3>
On 18 January 2011 18:56, Simon M. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> > 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?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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.