hubfeenix.fi/app/controllers/profiles_controller.rb

61 lines
1.5 KiB
Ruby
Raw Normal View History

2023-01-15 23:17:22 +01:00
class ProfilesController < ApplicationController
before_action :set_profile, only: %i[ show edit update destroy ]
2023-06-12 14:47:54 +02:00
def teachers
@profiles = Profile.where(kind: :teacher).page( 1 ).per(50)
@header = "Meet Hub Feenix teachers and organizers"
render :index
2023-01-15 23:17:22 +01:00
end
def show
end
def new
2023-01-16 00:11:05 +01:00
kind = params[:kind]
2023-01-20 13:59:34 +01:00
kind = Profile.kinds.first unless Profile.kinds.include?(kind)
2023-01-16 00:11:05 +01:00
@profile = Profile.new kind: kind
2023-01-15 23:17:22 +01:00
end
def edit
authorize @profile
end
def create
@profile = Profile.new(profile_params)
@profile.member = current_member
if @profile.save
2023-01-16 00:11:05 +01:00
redirect_to member_path(current_member), notice: "Successfully created #{@profile.Kind} profile"
2023-01-15 23:17:22 +01:00
else
render :new, status: :unprocessable_entity
end
end
def update
authorize @profile
if @profile.update(profile_params)
2023-01-16 00:11:05 +01:00
redirect_to member_path(current_member), notice: "#{@profile.Kind} profile was updated."
2023-01-15 23:17:22 +01:00
else
render :edit, status: :unprocessable_entity
end
end
def destroy
authorize @profile
@profile.destroy
2023-01-16 00:11:05 +01:00
redirect_to member_path(current_member), notice: "#{@profile.Kind} profile was successfully destroyed."
2023-01-15 23:17:22 +01:00
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
2023-06-12 14:47:54 +02:00
params.require(:profile).permit(:name, :bio, :picture,:picture_cache,
:kind , :info)
2023-01-15 23:17:22 +01:00
end
end