clarion/app/controllers/management/personal_profiles_controlle...

96 lines
2.1 KiB
Ruby
Raw Normal View History

2015-07-28 15:43:19 +03:00
module Management
class PersonalProfilesController < ManagementController
def index
@conference = find_conference
2016-10-09 03:56:41 +03:00
@users = current_conference.participants
2015-07-28 15:43:19 +03:00
end
def toggle_admin
@conference = find_conference
@user = find_profile.user
@user.toggle_admin!
2019-04-28 02:12:54 +03:00
redirect_back fallback_location: {action: :show}
2015-07-28 15:43:19 +03:00
end
def show
@conference = find_conference
@profile = find_profile
@user = @profile.user
if not @profile
flash[:error] = "No profile, needs to be created"
redirect_to action: :edit
end
end
2015-07-30 21:19:03 +03:00
def new
@conference = find_conference
@user = User.find params[:user_id]
@profile = @user.build_personal_profile(@conference)
2015-07-30 21:19:03 +03:00
end
def create
@conference = find_conference
@user = User.find(profile_params[:user_id])
@profile = @user.build_personal_profile(@conference, profile_params)
2015-07-30 21:19:03 +03:00
if @profile.save
flash[:notice] = t('.successfully_created')
redirect_to management_conference_personal_profile_path(@profile, conference_id: @conference.id)
2015-07-30 21:19:03 +03:00
else
render action: :new
end
end
2015-07-28 15:43:19 +03:00
def edit
@conference = find_conference
@profile = find_profile
@user = @profile.user
end
def update
@conference = find_conference
@profile = find_profile
if @profile.update_attributes(profile_params)
redirect_to [:management, @conference, @profile]
else
render action: 'edit'
end
end
def destroy
@profile = find_profile
@profile.destroy
redirect_to action: :index
end
private
def find_profile
PersonalProfile.find(params[:id])
end
def find_conference
Conference.find(params[:conference_id])
end
def profile_params
params.require(:personal_profile).permit(
:picture,
:first_name,
:last_name,
:mobile_phone,
:biography,
:organisation,
:public_email,
:github,
:twitter,
2015-07-30 21:19:03 +03:00
:user_id
2015-07-28 15:43:19 +03:00
)
end
end
end