clarion/app/controllers/public/volunteerships_controller.rb

52 lines
1.6 KiB
Ruby
Raw Normal View History

module Public
class VolunteershipsController < Public::ApplicationController
2019-04-28 02:15:39 +03:00
before_action :authenticate_user!, only: [:create, :destroy]
def index
@volunteer_teams = current_conference.volunteer_teams
end
def create
@volunteer_team = current_conference.volunteer_teams.find params[:volunteer_team_id]
@volunteership = @volunteer_team.volunteerships.build volunteer: current_user
@volunteership.build_proposition proposer: current_user, status: :undecided
if @volunteership.save
2019-04-28 21:10:54 +03:00
flash[:notice] = I18n.t("views.volunteerships.you_successfully_applied_for", team: @volunteership.volunteer_team.name)
else
2019-04-28 21:10:54 +03:00
flash[:error] = I18n.t("views.volunteerships.an error_occurred_while_applying")
end
after_save_redirect
end
def destroy
@volunteership = current_user.volunteerships.find params[:id]
if @volunteership.destroy
2019-04-28 21:10:54 +03:00
flash[:notice] = I18n.t("views.volunteerships.you_successfully_retracted_your_application_for", team: @volunteership.volunteer_team.name)
end
redirect_to volunteerships_path
end
private
def volunteership_params
params.require(:volunteership).permit(
:title, :subtitle, :track_id, :length, :language,
:abstract, :description, :notes, :agreement,
:volunteership_type_id
)
end
def after_save_redirect
if current_user.personal_profile(current_conference).present?
redirect_to volunteerships_path
else
redirect_to edit_personal_profile_path, alert: I18n.t(:please_fill_in_your_speaker_profile)
end
end
end
end