我有一个页面,用户可以在其中添加收藏夹。现在,页面将他们的帖子分类到收藏夹中,但按 .order(created_at: :desc) 对 Post 数据库 created_at 字段进行排序。如何更改它以使用 Vote 表及其 created_at frield。
@posts = Post.where(id: current_user.find_voted_items.map(&:id)).order(created_at: :desc).paginate(:page => params[:page], :per_page => 36)
这是相关的架构
create_table "votes", force: :cascade do |t|
t.integer "votable_id"
t.string "votable_type"
t.integer "voter_id"
t.string "voter_type"
t.boolean "vote_flag"
t.string "vote_scope"
t.integer "vote_weight"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "posts", force: :cascade do |t|
t.string "soundcloud"
t.string "title"
t.string "artist"
t.string "audio"
t.string "image"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "download"
t.integer "cached_votes_total", default: 0
t.integer "cached_votes_score", default: 0
t.integer "cached_votes_up", default: 0
t.integer "cached_votes_down", default: 0
t.integer "cached_weighted_score", default: 0
t.integer "cached_weighted_total", default: 0
t.float "cached_weighted_average", default: 0.0
end
谢谢