1

我在本地使用 sqlit3,在 heroku 使用 Postgre。

一切正常,直到我将文件上传到heroku。这是我的模型。

class User < ActiveRecord::Base
  belongs_to :unit

  has_friends
end

class Unit < ActiveRecord::Base
  attr_accessible :unit, :floor
  has_many :users
  belongs_to :block
end

class Block < ActiveRecord::Base
  attr_accessible :block, :units_attributes
  has_many :units, :dependent => :destroy
  accepts_nested_attributes_for :units, allow_destroy: true
  belongs_to :postalcode
end

class Postalcode < ActiveRecord::Base
  attr_accessible :postalcode, :blocks_attributes
  has_many :blocks, :dependent => :destroy
  accepts_nested_attributes_for :blocks, allow_destroy: true
  belongs_to :neighbourhood
end

class Neighbourhood < ActiveRecord::Base
  attr_accessible :name, :streetname, :postalcodes_attributes
  has_many :postalcodes, :dependent => :destroy
  has_many :blocks, :through => :postalcodes
  has_many :units, :through => :blocks
  has_many :users, :through => :units
  accepts_nested_attributes_for :postalcodes, allow_destroy: true
  validates :name, :presence => true
  validates :streetname, :presence => true
end

我进行了故障排除,发现问题出在控制器中的这种方法上。

@neighbours = current_user.unit.block.postalcode.neighbourhood.users

虽然@neighbours = current_user.unit.block.postalcode.neighbourhood 工作得很好。

请帮忙,我很绝望,我已经尝试了一整天的谷歌搜索。

4

1 回答 1

1

查看类似问题的此答案

很可能出现错误WHERE "postalcodes"."neighbourhood_id" = 1,表明neighbourhood_id在邮政编码表中创建为字符串,而不是整数。

相应地按照答案中提到的步骤,并将其更改为整数。

于 2012-10-22T04:35:21.417 回答