This is the error that keeps appearing. I don''t understand why "@tblusers" is not correct. Can anyone help? NoMethodError in Tblregisteredphone#new Showing app/views/tblregisteredphone/new.rhtml where line #20 raised: You have a nil object when you didn''t expect it! You might have expected an instance of Array. The error occured while evaluating nil.each Extracted source (around line #20): 17: <p> 18: <b>User:</b><br/> 19: <select name="tblregisteredphone[tbluser_id]"> 20: <% @tblusers.each do |tbluser| %> 21: <option value="<%= tbluser.id %>" 22: <%= tbluser.txtforename %> 23: </option> RAILS_ROOT: ./script/../config/.. Application Trace | Framework Trace | Full Trace #{RAILS_ROOT}/app/views/tblregisteredphone/new.rhtml:20 Alana -- Posted via http://www.ruby-forum.com/.
On 04/04/06, Alana <alana@c4l.co.uk> wrote:> This is the error that keeps appearing. I don''t understand why > "@tblusers" is not correct. Can anyone help?What does the code for the "new" method in your controller say? I can only assume that @tblusers isn''t being set properly there, but if you post the method then we can help more. Thanks, David
> What does the code for the "new" method in your controller say? I can > only assume that @tblusers isn''t being set properly there.The code for my "new" method in the controller is as follows: def new @tblregisteredphone = Tblregisteredphone.new @tbluser = Tbluser.find_all end Thanks David, Alana -- Posted via http://www.ruby-forum.com/.
On 04/04/06, Alana <alana@c4l.co.uk> wrote:> The code for my "new" method in the controller is as follows: > > def new > @tblregisteredphone = Tblregisteredphone.new > @tbluser = Tbluser.find_all > end >Ah - the problem is that you set @tbluser in your controller, but then use @tblusers in the view! Pretty easy to fix :-) David
Thanks for your help! I''m new to rails and ruby, so learning as I go! :) Alana -- Posted via http://www.ruby-forum.com/.
I''m getting the following error and have checked and double checked all my table and field names are correct. Only the field names have uppercase letters in them. Where am I going wrong? NoMethodError in Tblregisteredphone#list Showing app/views/tblregisteredphone/list.rhtml where line #23 raised: You have a nil object when you didn''t expect it! The error occured while evaluating nil.txtForename Extracted source (around line #23): 20: </font> 21: </td> 22: <td> 23: <%= link_to tblregisteredphone.tbluser.txtForename, 24: :action => "list", 25: :tbluser => "#{tblregisteredphone.tbluser.txtForename}" %> 26: </td> Alana -- Posted via http://www.ruby-forum.com/.
Hi Alana ~ Are you sure you have an object tblregisteredphone that has data? If that is one of your models, you need to create an instance of that model. Might try putting <%= debug tblregisteredphone %> in your view to see if the object is being created. I would need to see what the controller is doing to offer some more help. ~ Ben On 4/7/06, Alana <alana@c4l.co.uk> wrote:> > I''m getting the following error and have checked and double checked all > my table and field names are correct. Only the field names have > uppercase letters in them. Where am I going wrong? > > NoMethodError in Tblregisteredphone#list > > Showing app/views/tblregisteredphone/list.rhtml where line #23 raised: > > You have a nil object when you didn''t expect it! > The error occured while evaluating nil.txtForename > > Extracted source (around line #23): > > 20: </font> > 21: </td> > 22: <td> > 23: <%= link_to tblregisteredphone.tbluser.txtForename, > 24: :action => "list", > 25: :tbluser => "#{tblregisteredphone.tbluser.txtForename}" > %> > 26: </td> > > Alana > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Ben Reubenstein http://www.benr75.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060407/72281745/attachment.html
Hi Ben, tblregisteredphone definitely has data in it. The model for it is as follows: class Tblregisteredphone < ActiveRecord::Base belongs_to :tbluser, set_primary_key(:TblRegisteredPhonesID) end The model for the table it is related to (tbluser) is as follows: class Tbluser < ActiveRecord::Base has_many :tblregisteredphones set_primary_key(:TblUsersID) end Thanks for your help, Alana -- Posted via http://www.ruby-forum.com/.
Hi, I created a test database using the conventional rails naming such as "id" for primary key and "tblname_id" for foreign keys. I then recreated the rails database for an existing database and had to use their primary and foreign key names. Since then, even though I have set the primary and foreign keys in the table models, I have been getting errors such as this no method error. Can anyone please help me with this? Alana -- Posted via http://www.ruby-forum.com/.
Alana wrote:> I''m getting the following error and have checked and double checked all > my table and field names are correct. Only the field names have > uppercase letters in them. Where am I going wrong? > > NoMethodError in Tblregisteredphone#list > > Showing app/views/tblregisteredphone/list.rhtml where line #23 raised: > > You have a nil object when you didn''t expect it! > The error occured while evaluating nil.txtForename > > Extracted source (around line #23): > > 20: </font> > 21: </td> > 22: <td> > 23: <%= link_to tblregisteredphone.tbluser.txtForename, > 24: :action => "list", > 25: :tbluser => "#{tblregisteredphone.tbluser.txtForename}" %> > 26: </td>Tblregisteredphone.tbluser is nil. You didn''t initialize Tblregisteredphone[tbluser_id]. What does your controller look like? -- Ray
Hi Ray,> Tblregisteredphone.tbluser is nil. > > You didn''t initialize Tblregisteredphone[tbluser_id]. > > What does your controller look like?My tblregisteredphone controller is as follows: class Tblregisteredphone < ActiveRecord::Base set_table_name "tblregisteredphones" belongs_to :tbluser, :foreign_key => "intUserID" set_primary_key(:TblRegisteredPhonesID) end "tbluser" has a primary key called "TblUsersID" and the foreign key in "tblregisteredphones" is called "intUserID". Thanks for your help, Alana -- Posted via http://www.ruby-forum.com/.
Alana wrote:> Hi Ray, > >> Tblregisteredphone.tbluser is nil. >> >> You didn''t initialize Tblregisteredphone[tbluser_id]. >> >> What does your controller look like? > > My tblregisteredphone controller is as follows: > > class Tblregisteredphone < ActiveRecord::Base > set_table_name "tblregisteredphones" > belongs_to :tbluser, > :foreign_key => "intUserID" > set_primary_key(:TblRegisteredPhonesID) > end > > "tbluser" has a primary key called "TblUsersID" and the foreign key in > "tblregisteredphones" is called "intUserID".That''s your model. We need to see your controller, and probably your data too. -- Ray
Sorry, the controller is as follows. What data do you need? class TblregisteredphoneController < ApplicationController layout "standard-layout" scaffold :tblregisteredphone def delete Tblregisteredphone.find(@params[''id'']).destroy redirect_to :action => ''list'' end def create @tblregisteredphone = Tblregisteredphone.new(@params[''tblregisteredphone'']) @tblregisteredphone.txtregisterdatetime = Time.now if @tblregisteredphone.save redirect_to :action => ''list'' else render_action ''new'' end end def new @tblregisteredphone = Tblregisteredphone.new @tbluser = Tbluser.find_all end def list @tbluser = @params[''tbluser''] @tblregisteredphones = Tblregisteredphone.find_all end def edit @tblregisteredphone = Tblregisteredphone.find(@params["id"]) @tbluser = Tbluser.find_all end end Alana -- Posted via http://www.ruby-forum.com/.
Alana wrote:> Sorry, the controller is as follows. What data do you need?The list method doesn''t initialize tblregisteredphone. Is that initialized somewhere in your view before the exception? Also, your create method doesn''t initialize tbluser_id. Do all of your entries in tblregisteredphone have non-null tbluser_id? -- Ray
Ray Baxter wrote:> 1. The list method doesn''t initialize tblregisteredphone. Is that > initialized somewhere in your view before the exception? > > 2. Also, your create method doesn''t initialize tbluser_id. > 3. Do all of your entries in tblregisteredphone have non-null tbluser_id?1. This line is in my view: <% @tblregisteredphones.each do |tblregisteredphone| %> Is this correct? 2. How do I initialize intUserID (the foreign key in tblregistered phones) and is this the correct naming convention? My tables are as follows: "tblusers" - primary key "TblUsersID" "tblregisteredphones" - primary key "TblRegisteredPhonesID" - foreign key "intUserID" 3. All of the entries have a non-null intUserID. Thank you for your help, Alana -- Posted via http://www.ruby-forum.com/.
Hi, I''m new to rails and have stumbled across this error. Where am I going wrong?! NoMethodError in Registeredphone#new Showing app/views/registeredphone/new.rhtml where line #15 raised: undefined method `user_id'' for #<Registeredphone:0x3874030> Extracted source (around line #15): 12: <select name="registeredphone[user_id]"> 13: <% @user.each do |user| %> 14: <option value="<%= user.id %>" 15: <%= ''selected'' if user.id == @registeredphone.user_id %>> 16: <%= user.txtForename %> 17: </option> 18: <% end %> My controller is as follows: class RegisteredphoneController < ApplicationController layout "standard-layout" scaffold :registeredphone def delete Registeredphone.find(@params[''id'']).destroy redirect_to :action => ''list'' end def create @registeredphone = Registeredphone.new(@params[''registeredphone'']) @registeredphone.txtregisterdatetime = Time.now if @registeredphone.save redirect_to :action => ''list'' else render_action ''new'' end end def new @registeredphone = Registeredphone.new @user = User.find_all end def list @user = @params[''user''] @registeredphones = Registeredphone.find_all end def edit @registeredphone = Registeredphone.find(@params["id"]) @user = User.find_all end end Any help would be appreciated!! Alana -- Posted via http://www.ruby-forum.com/.
Alana Murphy wrote:> Hi, > > I''m new to rails and have stumbled across this error. Where am I going > wrong?! > > > NoMethodError in Registeredphone#new > > Showing app/views/registeredphone/new.rhtml where line #15 raised: > > undefined method `user_id'' for #<Registeredphone:0x3874030> > > Extracted source (around line #15): > > 12: <select name="registeredphone[user_id]"> > 13: <% @user.each do |user| %> > 14: <option value="<%= user.id %>" > 15: <%= ''selected'' if user.id == @registeredphone.user_id %>> > 16: <%= user.txtForename %> > 17: </option> > 18: <% end %> > > My controller is as follows:This error is telling you that your Registeredphone object doesn''t have a user_id method which you attempt to use on line 15 of your view. This could be because your registeredphones table doesn''t have a user_id column, or because you didn''t define a user_id method in your Registeredphone model. -- Ray