58 lines
1.4 KiB
Ruby
58 lines
1.4 KiB
Ruby
class ProfilesController < ApplicationController
|
|
before_action :set_profile, only: %i[ show edit update destroy ]
|
|
|
|
def index
|
|
@profiles = Profile.page params[:page]
|
|
end
|
|
|
|
def show
|
|
end
|
|
|
|
def new
|
|
kind = params[:kind]
|
|
kind = Profile.kinds.first unless Profile.kinds.include?(kind)
|
|
@profile = Profile.new kind: kind
|
|
end
|
|
|
|
def edit
|
|
authorize @profile
|
|
end
|
|
|
|
def create
|
|
@profile = Profile.new(profile_params)
|
|
@profile.member = current_member
|
|
|
|
if @profile.save
|
|
redirect_to member_path(current_member), notice: "Successfully created #{@profile.Kind} profile"
|
|
else
|
|
render :new, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def update
|
|
authorize @profile
|
|
if @profile.update(profile_params)
|
|
redirect_to member_path(current_member), notice: "#{@profile.Kind} profile was updated."
|
|
else
|
|
render :edit, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
authorize @profile
|
|
@profile.destroy
|
|
redirect_to member_path(current_member), notice: "#{@profile.Kind} 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,:picture_cache, :kind)
|
|
end
|
|
end
|