0
嗨我有一個多對多的關聯,其中'帖子'有很多'感覺',我想弄清楚如何找到具有用戶特定感覺的所有帖子。我的感覺模型具有「名稱」屬性。Rails 3:在has_many協會上調用數據庫
class User < ActiveRecord::Base
has_many :posts, :dependent => :destroy
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
class Post < ActiveRecord::Base
has_many :feelingships
has_many :feelings, :through => :feelingships
belongs_to :user
end
class Feeling < ActiveRecord::Base
has_many :feelingships
has_many :posts, :through => :feelingships
end
class Feelingship < ActiveRecord::Base
belongs_to :post
belongs_to :feeling
attr_accessible :post_id, :feeling_id
end
我試過,但它說我有錯誤的聯想:「的ActiveRecord :: ConfigurationError:協會命名爲‘感覺’沒有被發現;也許你拼錯了嗎?」
def feeling
@user = User.find(params[:id])
@feed_items= @user.posts.includes(:feeling).where(
['`feelings`.name = ?', params[:feeling]])
@feed_items = @feed_items.paginate(:per_page => "10", :page => params[:page])
render 'shared/_feed', :layout => 'head_layout'
end
什麼是 「飼料」,你在@user打電話?它應該可能是「帖子」,而不是 – Nycen
aye,只是現在修正的拼寫錯誤 –