Merge pull request #639 from differentreality/devise_partials

Move common views to partial
This commit is contained in:
Stella Rouzi 2015-06-12 12:30:51 +03:00
commit 0013a3a814
19 changed files with 180 additions and 138 deletions

View file

@ -14,8 +14,16 @@ class ConferenceRegistrationsController < ApplicationController
redirect_to root_path, alert: 'You need to sign in or sign up before continuing.'
return
end
# avoid openid sign_in to redirect to register/new when the sign_in user had already a registration
if current_user && @conference.user_registered?(current_user)
redirect_to edit_conference_conference_registrations_path(@conference.short_title)
end
@registration = Registration.new
@registration.build_user
# @user variable needs to be set so that _sign_up_form_embedded works properly
@user = @registration.build_user
end
def show
@ -27,9 +35,16 @@ class ConferenceRegistrationsController < ApplicationController
def edit; end
def create
@registration = Registration.new(registration_params)
@registration.conference = @conference
@registration.user = current_user if current_user
@registration = @conference.registrations.new(registration_params)
if current_user.nil?
# @user variable needs to be set so that _sign_up_form_embedded works properly
@user = @registration.build_user(user_params)
else
@user = current_user
end
@registration.user = @user
if @registration.save
# Trigger ahoy event
@ -47,7 +62,7 @@ class ConferenceRegistrationsController < ApplicationController
redirect_to conference_conference_registrations_path(@conference.short_title)
end
else
flash[:error] = "An error prohibited the registration for #{@conference.title}: "\
flash[:error] = "Could not create your registration for #{@conference.title}: "\
"#{@registration.errors.full_messages.join('. ')}."
render :new
end
@ -58,7 +73,7 @@ class ConferenceRegistrationsController < ApplicationController
redirect_to conference_conference_registrations_path(@conference.short_title),
notice: 'Registration was successfully updated.'
else
flash[:error] = "An error prohibited the registration for #{@conference.title}: "\
flash[:error] = "Could not update your registration for #{@conference.title}: "\
"#{@registration.errors.full_messages.join('. ')}."
render :edit
end
@ -70,7 +85,7 @@ class ConferenceRegistrationsController < ApplicationController
notice: "You are not registered for #{@conference.title} anymore!"
else
redirect_to root_path,
error: "An error prohibited deleting the registration for #{@conference.title}: "\
error: "Could not update your registration for #{@conference.title}: "\
"#{@registration.errors.full_messages.join('. ')}."
end
end
@ -85,6 +100,10 @@ class ConferenceRegistrationsController < ApplicationController
end
end
def user_params
params.require(:user).permit(:username, :email, :name, :password, :password_confirmation)
end
def registration_params
params.require(:registration).
permit(