I’m wondering…
(1) what should be the correct associations for 2 different tables both with 2 same columns
(2) how do i display the user list in views with for loop
So one table is called Attending and has 2 columns: Events & Users
Another table is called NotAttending and has 2 columns: Events & Users
class User < ActiveRecord::Base
has_many :attending
has_many :notattending
has_many :events, :through => :attending
has_many :events, :through => :notattending
end
class Event < ActiveRecord::Base
has_many :attending
has_many :notattending
has_many :users, :through => :attending
has_many :users, :through => :notattending
end
class Attending < ActiveRecord::Base
belongs_to :user
belongs_to :event
end
class Notattending < ActiveRecord::Base
belongs_to :user
belongs_to :event
end
How would I display the list of users for attending and notattending in the views? I get error undefined method users for nil:NilClass
<% for user in @attending.user %>
<%= user.name %></br>
<% end %>
Thanks!
ASIDE: why not combine Attending and Nonattending into one table with three columns, event, user, and is_attending (true if attending, false if not attending)?
But no matter, let’s assume the data model is fixed…
You cannot use has_many :users twice. You could choose to make another method: