Created
December 29, 2011 15:15
-
-
Save procload/1534514 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create | |
@user = current_user | |
event = Event.find(params[:event_id]) | |
if @user.events.find_by_id(event) | |
redirect_to event, notice: 'You can\'t enroll to the same event twice. Duh.' | |
return | |
else | |
@enrollment = @user.enrollments.build(event: event) | |
end | |
respond_to do |format| | |
if @enrollment.save | |
format.html { redirect_to @user, notice: 'Successfully enrolled' } | |
format.json { render json: @user, status: :created, location: @user } | |
else | |
format.html { render action: "new" } | |
format.json { render json: @enrollment.errors, status: :unprocessable_entity } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment