Im trying to add new records to my joins table. but when ever i click my link to do so i get this error
uninitialized constant Channel::UsersChannel
here is the code
<%= link_to "Subscribe to Channel", subscribe_path(channel, current_user) %>
def subscribe
@channel = Channel.find(params[:channel_id])
@user = current_user
@channel.users << @user
@channel.save
flash[:notice] = 'You have subscribed to' + @channel.name
redirect_to @channel
end
class User < ActiveRecord::Base
acts_as_authentic
ROLES = %w[admin moderator subscriber]
#join between users and messages
has_many :user_messages
has_many :messages, :through => :user_messages
#join between users and channels
has_many :user_channels
has_many :channels , :through => :users_channels
#join between mods and channels
has_many :channel_mods
has_many :manages, :class_name =>"channel", :through =>:channel_mods
named_scope :with_role, lambda { |role| {:conditions => "roles_mask & #{2**ROLES.index(role.to_s)} > 0 "} }
def roles
ROLES.reject { |r| ((roles_mask || 0) & 2**ROLES.index(r)).zero? }
end
def roles=(roles)
self.roles_mask = (roles & ROLES).map { |r| 2**ROLES.index(r) }.sum
end
def role_symbols
role.map do |role|
role.name.underscore.to_sym
end
end
end
class UsersChannels < ActiveRecord::Base
belongs_to :user
belongs_to :channel
end
class Channel < ActiveRecord::Base
# acts_as_taggable
# acts_as_taggable_on :tags
has_many :messages
has_many :channel_mods
has_many :moderators , :class_name =>"User", :through => :channel_mods
has_many :users_channels
has_many :users, :through => :users_channels
end