Browse Source

ransack ok

main
pvincent 4 months ago
parent
commit
78fc21514a
  1. 3
      app/controllers/scores_controller.rb
  2. 2
      app/models/score.rb

3
app/controllers/scores_controller.rb

@ -5,7 +5,7 @@ class ScoresController < ApplicationController
before_action :set_score, only: %i[show edit update destroy]
def index
@q = Score.all.ransack
@q = Score.all.ransack(q_params)
@pagy, @scores = pagy(@q.result)
end
@ -47,4 +47,5 @@ class ScoresController < ApplicationController
def set_score = @score = Score.find(params[:id])
def score_params = params.require(:score).permit(:name, :grade)
def q_params = params.fetch(:q, {}).permit!
end

2
app/models/score.rb

@ -2,4 +2,6 @@
class Score < ApplicationRecord
validates :name, presence: true
validates :grade, presence: true
def self.ransackable_attributes(_ = nil) = authorizable_ransackable_attributes
end
Loading…
Cancel
Save