命名的錯誤,我想在我加入表在控制器
NameError在 SubscriptionsController#新
未初始化的常量 頻道:: ChannelsUser
創建一個記錄時出現此錯誤訂閱控制器
class SubscriptionsController < ApplicationController
helper_method :current_user_session, :current_user
filter_parameter_logging :password, :password_confirmation
def new
@channel = Channel.find(params[:channel_id])
@user = current_user
@channel.subscribers << @user
@channel.save
flash[:notice] = "You have subscribed to: " [email protected]
redirect_to @channel
end
end
端
用戶模型
class User < ActiveRecord::Base
acts_as_authentic
ROLES = %w[admin moderator subscriber]
#Each user can subscribe to many channels
has_many :channels_users
has_many :subscriptions, :class_name => "Channel", :through => :channels_users
#Each user who is a moderator can moderate many channels
has_many :channel_mods
has_many :channels, :through => :channel_mods
#Each user can receive many messages
has_many :messages_users , :dependent => :destroy
has_many :reciepts , :class_name => "User", :through => :messages_users
#Filter users by role(s)
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 Channel < ActiveRecord::Base
#Each channel owns many or no messages
has_many :messages
#Each channel is own by one moderator
has_many :channel_mods
has_many :moderators, :class_name =>'User', :through =>:channel_mod
#Each channel can have and belong to many or no users
has_many :channels_users
has_many :subscribers, :class_name => 'Users' , :through => :channels_users
end
ChannelsUsers模型
class ChannelsUsers < ActiveRecord::Base
belongs_to :user
belongs_to :channel
end
我試過這樣做的第二種方式,但沒有進展,如果這樣做,我必須重新生成文件的第一種方式是如何?第一次我做軌道克模型ChannelsUsers – 2010-12-04 04:23:34
對不起,有一個錯字的答案。它應該是`:class_name =>'ChannelUsers'`。我編輯了答案。 – Swanand 2010-12-04 04:25:35