add trashable to question

This commit is contained in:
João Geonizeli
2022-08-05 23:40:03 +00:00
parent 9917441fe4
commit 5005d7ca68
6 changed files with 36 additions and 2 deletions

View File

@@ -1,6 +1,30 @@
ActiveAdmin.register Question do ActiveAdmin.register Question do
permit_params :authorship, :authorship_year, :check_type, :difficulty, :status, :subject_id permit_params :authorship, :authorship_year, :check_type, :difficulty, :status, :subject_id
scope :all, default: true
scope :trashed
controller do
def show
@question = Question.unscoped.find_by!(permitted_params[:question])
end
def edit
@question = Question.unscoped.find_by!(permitted_params[:question])
end
def destroy
@question = Question.unscoped.find(permitted_params[:id])
if @question.deleted_at
redirect_to admin_questions_path, notice: t('active_admin.question.already_destroyed')
else
@question.destroy
redirect_to admin_questions_path, notice: t('active_admin.question.succesfully_destroyed')
end
end
end
index do index do
selectable_column selectable_column
id_column id_column

View File

@@ -32,6 +32,7 @@
# fk_rails_... (user_id => users.id) # fk_rails_... (user_id => users.id)
# #
class Question < ApplicationRecord class Question < ApplicationRecord
include Trashable
extend Enumerize extend Enumerize
belongs_to :user belongs_to :user

View File

@@ -147,3 +147,6 @@ pt-BR:
user: user:
succesfully_destroyed: 'Usuário removido com sucesso.' succesfully_destroyed: 'Usuário removido com sucesso.'
already_destroyed: "Usuário já está removido." already_destroyed: "Usuário já está removido."
question:
succesfully_destroyed: 'Questão removido com sucesso.'
already_destroyed: "Questão já está removido."

View File

@@ -0,0 +1,5 @@
class AddDeletedAtToQuestion < ActiveRecord::Migration[7.0]
def change
add_column :questions, :deleted_at, :datetime
end
end

3
db/schema.rb generated
View File

@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2022_07_31_232807) do ActiveRecord::Schema[7.0].define(version: 2022_08_05_233401) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@@ -93,6 +93,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_07_31_232807) do
t.text "support" t.text "support"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.datetime "deleted_at"
t.index ["subject_id"], name: "index_questions_on_subject_id" t.index ["subject_id"], name: "index_questions_on_subject_id"
t.index ["user_id"], name: "index_questions_on_user_id" t.index ["user_id"], name: "index_questions_on_user_id"
end end

View File

@@ -45,7 +45,7 @@ fi
###################### ######################
yellow_text 'Preparing the database...' yellow_text 'Preparing the database...'
docker-compose run --rm web rails db:create docker-compose run --rm rails rails db:create
green_text 'Everything ready to run!' green_text 'Everything ready to run!'