Benjamin Meichsner
2007-Aug-30 09:50 UTC
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 %> <tr> <td> <%= link_to task.name, :controller => "tasks", :action => "show", :id => task %> </td> <td> <% unless task.users.empty? owner = Array.new task.assignments.each do |ass| if ass.accepted? nick = "<span class=''accepted''>#{ass.user.nick.to_s}</span>" else nick = "<span class=''unaccepted''>#{ass.user.nick.to_s}</span>" end owner << nick end %> <%= owner.join(", ")%> <% end %> </td> <% 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 -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---