It would help to see the model and schema for the user table, which is
where the problem seems to be.
I notice that you say “belongs_to :user” and then you try to reference
tblregisteredphone.tbluser.txtForename, though. Shouldn’t it be
tblregisteredphone.user.txtForename instead? Also, is the user table
called users or tblusers, and how is it referred to in its model?
You really should name things more consistently. It’s not a good sign
when you’re confused by your own naming convention. If these are legacy
tables and you’re aliasing them in the models to simpler names, you
should pick one way to do it and stick to it throughout to prevent more
problems like this, nu?
Alana wrote:
Where can I define the method ‘tbluser’ in this error?
NoMethodError in Tblregisteredphone#list
Showing app/views/tblregisteredphone/list.rhtml where line #23 raised:
The users table is called “tblusers” and the model is as follows:
class Tbluser < ActiveRecord::Base
set_table_name “tblusers”
has_many :tblregisteredphones
set_primary_key(:TblUsersID)
end
I am using legacy tables and am new to rails so am finding it difficult
to understand how the aliases work. Once I’ve set the aliases, can I
then refer to them everywhere else (controller and rhtml files) as as
the alias name? I had no problems creating this database as a test using
the normal rails naming conventions, but since using the legacy schema,
I have been unable to get it to work properly.
Thank you for your help, it is much appreciated.
Alana
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.