Undefined method error

class Task < ActiveRecord::Base
belongs_to :court
has_many :workflow_tasks
has_many :task_users, :dependent => :destroy
has_many :court_users, :through => :task_users
end

class TaskUser < ActiveRecord::Base
belongs_to :task
belongs_to :court_user
end

I accessed the court_user as follows:

task.task_users.collect{|task_user|task_user.court_user.user.name}

Error:

undefined method `court_user’ for #TaskUser:0x60f4320

Anyone knows the solution. It only happens in the development mode. It
seams the autoloading not working properly.

If I find the TaskUser directly like following it will work, but this is
not the right solution.

task_users = TaskUser.find(:all, :conditions=>[‘task_id=?’,task.id])
task_users.collect{|task_user|task_user.court_user.user.name}

Frederick C. wrote:

undefined method `court_user’ for #TaskUser:0x60f4320

Anyone knows the solution. It only happens in the development mode. It
seams the autoloading not working properly.

do you ever require a class that could be autoloaded? that can fox
autoloading. There was a thread about this recently here.

Fred

Iam sorry, I couldn’t get your solution for this issue my friend

undefined method `court_user’ for #TaskUser:0x60f4320

Anyone knows the solution. It only happens in the development mode. It
seams the autoloading not working properly.

do you ever require a class that could be autoloaded? that can fox
autoloading. There was a thread about this recently here.

Fred

Ayyanar Aswathaman wrote:

Frederick C. wrote:

undefined method `court_user’ for #TaskUser:0x60f4320

Anyone knows the solution. It only happens in the development mode. It
seams the autoloading not working properly.

do you ever require a class that could be autoloaded? that can fox
autoloading. There was a thread about this recently here.

Fred

Iam sorry, I couldn’t get your solution for this issue my friend

Anyone knows?

court_user is not defined on TaskUser.

On Dec 5, 2007 2:15 PM, Ayyanar Aswathaman
[email protected]
wrote:

Fred

Iam sorry, I couldn’t get your solution for this issue my friend

Anyone knows?

Posted via http://www.ruby-forum.com/.


Ryan B.

task_user belongs_to court_user Ryan. It is defined in the TaskUser

Ahh yes, but is it defined the other way around? Does a CourtUser have
any
relationship defined to task_user inside court_user.rb?

On Dec 5, 2007 2:23 PM, Ayyanar Aswathaman
[email protected]
wrote:

task_user belongs_to court_user Ryan. It is defined in the TaskUser

Posted via http://www.ruby-forum.com/.


Ryan B.

No. I will tell you the table structure:

task_users

task_id
court_user_id

court_users

court_id
user_id

users

name
password

I’m telling you that you haven’t defined it inside the file
app/models/court_user.rb! Please listen carefully, it stops me repeating
myself.

You need to either have a belongs_to :task_user or a has_one :task_user
or…
a task_user method defined on CourtUser.

Your table structure has nothing to do with this.

On Dec 5, 2007 3:06 PM, Ayyanar Aswathaman
[email protected]
wrote:

court_users
Posted via http://www.ruby-forum.com/.


Ryan B.

Ryan B. wrote:

I’m telling you that you haven’t defined it inside the file
app/models/court_user.rb! Please listen carefully, it stops me repeating
myself.

You need to either have a belongs_to :task_user or a has_one :task_user
or…
a task_user method defined on CourtUser.

Your table structure has nothing to do with this.

On Dec 5, 2007 3:06 PM, Ayyanar Aswathaman
[email protected]
wrote:

court_users
Posted via http://www.ruby-forum.com/.


Ryan B.

Yeah, we have defined
has_many :task_users in the court_user.rb.

The solution is simple: You have defined a has_many :task_users on
court_user meaning that there is no task_user (note the lack of an S)
method
on court_user.

Either you define it as has_one :task_user or reference it as
task_users.

On Dec 5, 2007 4:35 PM, Ayyanar Aswathaman
[email protected]
wrote:

Still not working. I will try out and post the solution. Thanks Ryan

Posted via http://www.ruby-forum.com/.


Ryan B.

The required classes were not included in the task_user.rb.

require ‘court_user.rb’.

I missed this somehow.

Thanks all for your support.

Still not working. I will try out and post the solution. Thanks Ryan

This is a shot in the dark since I’m really struggling in
understanding how your tables work together, but instead of,
“task.task_users.collect{|task_user|
task_user.court_user.user.name}”
how about,
“task.task_users.collect{|task_user|
task_user.court_users.user.name}”
or this,
“task.task_users.collect{|task_user|task_user.users.name}”

On Dec 4, 3:21 am, Ayyanar Aswathaman <rails-mailing-l…@andreas-