Has_many through, model lost their methods after second load

hello

I’m using the has_many through association, because i want additional
attributes in the assignment-table. my association looks like this:

class Task < ActiveRecord::Base
has_many :assignments, :dependent => :destroy
has_many :users, :through => :assignments

class Assignment < ActiveRecord::Base
belongs_to :user
belongs_to :task
end

class User < ActiveRecord::Base
has_many :assignments, :dependent => :destroy
has_many :tasks, :through => :assignments

my Assignment-Model has also the attribut “accepted”. When I search for
unaccepted Tasks for a certain user I use the class-method:

class User …
def unaccepted_tasks
self.tasks.find :all, :conditions => [“accepted = ?”, false], :order
=> “due_date DESC”
end

Ok. that works. but when I now try loop over the tasks and use its own
method users (task.users…), i get an error.

my controller:
def myTasks
@tasks = @current_user.unaccepted_tasks
end

my view:
<%for task in @tasks %>



<%= link_to task.name, :controller => “tasks”, :action =>
“show”, :id => task %>


<% unless task.users.empty?
owner = Array.new
task.assignments.each do |ass|
if ass.accepted?
nick = “#{ass.user.nick.to_s}
else
nick = “#{ass.user.nick.to_s}”
end
owner << nick
end %>
<%= owner.join(", ")%>
<% end %>

<% end %>

the error:
undefined method `users’ for #Task:0xb69dc964

funny information. the first time I load the action myTaks works. but
the second (and later) request fails.

Any ideas?

greetings
benni

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs