add trashable to question
This commit is contained in:
@@ -1,6 +1,30 @@
|
||||
ActiveAdmin.register Question do
|
||||
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
|
||||
selectable_column
|
||||
id_column
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
# fk_rails_... (user_id => users.id)
|
||||
#
|
||||
class Question < ApplicationRecord
|
||||
include Trashable
|
||||
extend Enumerize
|
||||
|
||||
belongs_to :user
|
||||
|
||||
@@ -147,3 +147,6 @@ pt-BR:
|
||||
user:
|
||||
succesfully_destroyed: 'Usuário removido com sucesso.'
|
||||
already_destroyed: "Usuário já está removido."
|
||||
question:
|
||||
succesfully_destroyed: 'Questão removido com sucesso.'
|
||||
already_destroyed: "Questão já está removido."
|
||||
|
||||
5
db/migrate/20220805233401_add_deleted_at_to_question.rb
Normal file
5
db/migrate/20220805233401_add_deleted_at_to_question.rb
Normal 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
3
db/schema.rb
generated
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# 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
|
||||
enable_extension "plpgsql"
|
||||
|
||||
@@ -93,6 +93,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_07_31_232807) do
|
||||
t.text "support"
|
||||
t.datetime "created_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 ["user_id"], name: "index_questions_on_user_id"
|
||||
end
|
||||
|
||||
@@ -45,7 +45,7 @@ fi
|
||||
######################
|
||||
|
||||
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!'
|
||||
|
||||
Reference in New Issue
Block a user