saucy/app/controllers/members_controller.rb

74 lines
1.8 KiB
Ruby
Raw Normal View History

2022-06-25 12:48:46 +00:00
class MembersController < ApplicationController
2022-06-25 22:45:47 +00:00
before_action :require_login
before_action :set_member, only: %i[ show edit update delete destroy ]
2022-06-25 12:48:46 +00:00
helper_method :sort_params
2022-07-16 10:27:43 +00:00
include MemberFilter
2022-06-25 12:48:46 +00:00
# GET /members
def index
2022-07-16 10:27:43 +00:00
@members = filtered_members
2022-06-25 12:48:46 +00:00
end
# GET /members/1
def show
end
# GET /members/new
def new
2023-03-31 01:35:11 +00:00
@member = Member.new(get_params)
2022-06-25 12:48:46 +00:00
end
# GET /members/1/edit
def edit
end
# POST /members
def create
@member = Member.new(member_params.merge(number: Member.maximum(:number) + 1))
2022-06-25 12:48:46 +00:00
if @member.save
@member.reset_status!
redirect_to @member, notice: "Member was successfully created."
else
render :new, status: :unprocessable_entity
end
end
# PATCH/PUT /members/1
def update
if @member.update(member_params)
@member.reload.reset_status!
redirect_to @member, notice: "Member was successfully updated."
else
render :edit, status: :unprocessable_entity
end
end
# GET /members/1/delete
def delete
end
# DELETE /members/1
def destroy
@member.remove_personal_information!
redirect_to members_path, notice: "Member personal data permanently removed."
end
2022-06-25 12:48:46 +00:00
private
# Use callbacks to share common setup or constraints between actions.
def set_member
@member = Member.find(params[:id])
end
# Only allow a list of trusted parameters through.
def member_params
2023-03-31 01:24:16 +00:00
params.fetch(:member, {}).permit(:display_name, :legal_name, :pronouns, :email, :identification_number, :category, :address, :joined_on, :expires_on, :wants_mailing_list, :prefers_postal)
2022-06-25 12:48:46 +00:00
end
2023-03-31 01:35:11 +00:00
def get_params
params.permit(:display_name, :legal_name, :pronouns, :email, :identification_number, :category, :address, :joined_on, :expires_on, :wants_mailing_list, :prefers_postal)
end
2022-06-25 12:48:46 +00:00
end