sarting to generalize profiles
This commit is contained in:
@ -2,12 +2,17 @@ class ApplicationController < ActionController::Base
|
||||
before_action :configure_permitted_parameters, if: :devise_controller?
|
||||
|
||||
include Pundit::Authorization
|
||||
|
||||
alias :current_user :current_member #for pundit
|
||||
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
|
||||
|
||||
protected
|
||||
|
||||
def configure_permitted_parameters
|
||||
devise_parameter_sanitizer.permit(:sign_up, keys: [:name])
|
||||
end
|
||||
|
||||
def user_not_authorized
|
||||
flash[:alert] = "You are not authorized to perform this action."
|
||||
redirect_back(fallback_location: root_path)
|
||||
end
|
||||
end
|
||||
|
@ -3,7 +3,7 @@ class MembersController < ApplicationController
|
||||
|
||||
# GET /members
|
||||
def index
|
||||
@members = Member.all
|
||||
@members = Member.page params[:page]
|
||||
end
|
||||
|
||||
# GET /members/1
|
||||
|
62
app/controllers/profiles_controller.rb
Normal file
62
app/controllers/profiles_controller.rb
Normal file
@ -0,0 +1,62 @@
|
||||
class ProfilesController < ApplicationController
|
||||
before_action :set_profile, only: %i[ show edit update destroy ]
|
||||
|
||||
# GET /profiles
|
||||
def index
|
||||
@profiles = Profile.page params[:page]
|
||||
end
|
||||
|
||||
# GET /profiles/1
|
||||
def show
|
||||
end
|
||||
|
||||
# GET /profiles/new
|
||||
def new
|
||||
@profile = Profile.new
|
||||
end
|
||||
|
||||
# GET /profiles/1/edit
|
||||
def edit
|
||||
authorize @profile
|
||||
end
|
||||
|
||||
# POST /profiles
|
||||
def create
|
||||
@profile = Profile.new(profile_params)
|
||||
@profile.member = current_member
|
||||
|
||||
if @profile.save
|
||||
redirect_to @profile, notice: "Successfully created Profile profile"
|
||||
else
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /profiles/1
|
||||
def update
|
||||
authorize @profile
|
||||
if @profile.update(profile_params)
|
||||
redirect_to @profile, notice: "Profile Profile was updated."
|
||||
else
|
||||
render :edit, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /profiles/1
|
||||
def destroy
|
||||
authorize @profile
|
||||
@profile.destroy
|
||||
redirect_to profiles_url, notice: "Profile was successfully destroyed."
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_profile
|
||||
@profile = Profile.find(params[:id])
|
||||
end
|
||||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def profile_params
|
||||
params.require(:profile).permit(:name, :bio, :picture)
|
||||
end
|
||||
end
|
@ -1,62 +0,0 @@
|
||||
class TeachersController < ApplicationController
|
||||
before_action :set_teacher, only: %i[ show edit update destroy ]
|
||||
|
||||
# GET /teachers
|
||||
def index
|
||||
@teachers = Teacher.page params[:page]
|
||||
end
|
||||
|
||||
# GET /teachers/1
|
||||
def show
|
||||
end
|
||||
|
||||
# GET /teachers/new
|
||||
def new
|
||||
@teacher = Teacher.new
|
||||
end
|
||||
|
||||
# GET /teachers/1/edit
|
||||
def edit
|
||||
authorize @teacher
|
||||
end
|
||||
|
||||
# POST /teachers
|
||||
def create
|
||||
@teacher = Teacher.new(teacher_params)
|
||||
@teacher.member = current_member
|
||||
|
||||
if @teacher.save
|
||||
redirect_to @teacher, notice: "Successfully created Teacher profile"
|
||||
else
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /teachers/1
|
||||
def update
|
||||
authorize @teacher
|
||||
if @teacher.update(teacher_params)
|
||||
redirect_to @teacher, notice: "Teacher Profile was updated."
|
||||
else
|
||||
render :edit, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /teachers/1
|
||||
def destroy
|
||||
authorize @teacher
|
||||
@teacher.destroy
|
||||
redirect_to teachers_url, notice: "Teacher was successfully destroyed."
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_teacher
|
||||
@teacher = Teacher.find(params[:id])
|
||||
end
|
||||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def teacher_params
|
||||
params.require(:teacher).permit(:name, :bio, :picture)
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user