我目前正在开发一个有mongoid和rails的项目。这是代码:
class Account
include Mongoid::Document
include Mongoid::Timestamps
field :account_name, type: String
has_many :groups
end
class Group
include Mongoid::Document
field :group_name, type: String
belongs_to :account
has_and_belongs_to_many :groups
end
class GroupsController < ApplicationController
before_filter :require_login, :find_company
def new
@group = @company.groups.new
end
def create
@group = @company.groups.new params[:group]
if @group.save
redirect_to people_path
else
render :new
end
end
private
def find_company
@company = current_account.groups.find(params[:company_id]) if params[:company_id]
end
end
正在返回的错误是:
@' is not allowed as an instance variable name (NameError)
./app/controllers/groups_controller.rb:5:in `new'
我似乎无法找到关于这个问题的谷歌搜索,但似乎问题在于has_and_belongs_to_many关系,但我不确定。
任何想法都会受到赞赏。
由于
答案 0 :(得分:1)
问题在于我误解了has_and_belongs_to_many。我已经解决了这个问题!
感谢大家的评论。
答案 1 :(得分:0)
对我来说,原因是数据库连接没有正确配置:?