在关联上获取未定义的方法qouted_table_name

时间:2013-09-17 05:18:33

标签: ruby-on-rails ruby-on-rails-3

我在修复正在使用rails 2应用程序的关联时遇到问题。我在本地计算机上出现此错误:

  

未注册方法`quoted_table_name'for Enrollment:Module

我似乎无法弄清楚错误的位置。

型号:

class Enrollment < ActiveRecord::Base
  belongs_to :user
end

class User < ActiveRecord::Base
  has_one :enrollment


  accepts_nested_attributes_for :enrollment
end

控制器:

class UsersController < ApplicationController
  def new
    @user = User.new
    @user.build_enrollment
  end
end

更新: 修复了该问题,因为模型的名称与rails应用程序的名称相同。

1 个答案:

答案 0 :(得分:0)

  1. 您是否运行rake db:migrate以确保表格存在
  2. 由于嵌套属性子句放错位置,请进行以下更改

    class Enrollment < ActiveRecord::Base
      belongs_to :user
    end
    
    class User < ActiveRecord::Base
      has_one :enrollment
    
      # This line belongs here right?
      accepts_nested_attributes_for :enrollment 
    end