2
我正在使用Devise來管理用戶模型。獲取用戶使用Devise創建的所有貼子
這裏的用戶模型,user.rb
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
acts_as_voter
has_many :topics
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
這裏的主題模式,topic.rb
class Topic < ActiveRecord::Base
acts_as_voteable
belongs_to :user
end
當我創建一個帖子,用戶ID存儲在 「USER_ID」主題專欄。我想要一個用戶個人資料頁面,該頁面應顯示他所發佈的所有帖子。在我的用戶的個人資料頁面視圖,我有,
<%= Topic.find_by_user_id(@user.id) %>
我有相同的用戶做了兩個帖子,
但是當我嘗試獲取用戶發佈的所有信息中, SQL命令的1這樣的LIMIT自動查詢,
也正因爲如此,該視圖fetchin g只有1個用戶發表的帖子。我如何獲取所有帖子?