2012-10-22 35 views
1

我使用sqlit3本地和Postgre爲heroku。Rails3 has_many通過本地工作,但在heroku失敗

一切工作正常,直到我上傳我的文件到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 

我troubleshooted,發現的問題是與在控制器此方法。

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

雖然@neighbours = current_user.unit.block.postalcode.neighbourhood工作完全正常。

請幫忙,我絕望了,我已經嘗試了一整天Google搜索。

回答

1

退房this answer to a similar issue

這是很可能的錯誤快到了從WHERE "postalcodes"."neighbourhood_id" = 1指示,而不是一個整數,neighbourhood_id在postalcodes表作爲字符串創建。

按照答案中提到的步驟相應地將其更改爲整數。

+1

差不多,但是。這是我的用戶模型unit_id,werid。但是,謝謝,我愛你:D – user1627056

相關問題