0

I am currently working on a project with mongoid and rails. Here is the code:

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

And the error that is being returned is:

@' is not allowed as an instance variable name (NameError)
./app/controllers/groups_controller.rb:5:in `new'

I can't seem to find much googling around for the issue, but it would appear the issue lies with the has_and_belongs_to_many relationship, but I am not certain.

Any ideas would be appreciated.

Thanks

4

2 回答 2

1

问题是我误解了has_and_belongs_to_many。我已经通过删除它解决了这个问题!

谢谢大家的评论。

于 2013-04-25T13:20:35.700 回答
0

对我来说,原因是数据库连接没有正确配置:?

于 2021-04-22T20:36:36.097 回答