basic sort for stories

This commit is contained in:
2023-01-24 00:22:29 +02:00
parent 609c750ada
commit 86d9421548
6 changed files with 34 additions and 1 deletions

View File

@ -2,7 +2,9 @@ class StoriesController < ApplicationController
before_action :set_story, only: %i[ show edit update destroy ]
def index
@stories = Story.all.page params[:page]
@q = Story.ransack(params[:q])
@q.sorts = 'created_at desc' if @q.sorts.empty?
@stories = @q.result(distinct: true).page( params[:page])
end
def show

View File

@ -1,4 +1,10 @@
= paginate @stories
.flex.justify-end
= sort_link(@q, :happened ,class: 'flex flex-nowrap text-md')
.border-r-4.mx-4
= sort_link(@q, :created_at , class: 'flex flex-nowrap text-md')
- @stories.each do |story|
= render_story(story)