最近、次のモデルを作成しました。
class User < ActiveRecord::Base
has_many :resources
has_many :resource_views, :through => :user_resource_views, :source => 'Resource'
end
class Resource < ActiveRecord::Base
belongs_to :user
has_many :resource_views, :through => :user_resource_views, :source => 'Resource'
end
class UserResourceView < ActiveRecord::Base
attr_accessible :resource_id, :user_id
belongs_to :resource
belongs_to :user_id
end
ここで、home#indexアクションで、@resourcesをcurrent_userの最後に表示されたリソースに設定します。どのように私が進むようにアドバイスしますか?おそらく、current_user.resource_views.find(:all、:order =>'created_at')に似たものですか?
SQLでは、次のようにします。
SELECT *
FROM Resource
WHERE id IN (SELECT * FROM UserResourceView WHERE user_id = current_user.id)
...しかし、その後、ORDER BY created_at、hmmm
私はそれを理解するまで、1日を通して定期的に進捗状況の更新を追加します。