Browse Source

ransack ok

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

2
app/models/score.rb

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