Created
January 8, 2012 03:01
-
-
Save robyurkowski/1576990 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
class RegistrationController < ApplicationController | |
before_filter :find_user | |
def create | |
if @user.save | |
add_reminders_to @user | |
else | |
render :new, :errors => "Something weird" | |
end | |
end | |
private | |
def find_user | |
@user = User.find_or_create_by_phone(params[:user][:phone]) | |
@user.save! if @user.new_record? | |
end | |
def add_reminders_to( user ) | |
## update user | |
# Ensure they have selected a notification type | |
# all is scoped to return workout, quotes and tips in order, first grabs the first. | |
if params[:workout] | |
@reminder = user.reminders.build( Workout.all.first.reminders.build( params[:reminder] ).attributes ) | |
if @reminder.save | |
redirect_to congrats_path | |
else | |
render :new, :error => "There was some validation error" | |
end | |
end | |
if params[:quote] | |
@quote = user.reminders.build( Quote.all.first.reminders.build( params[:reminder] ).attributes ) | |
if @quote.save | |
redirect_to congrats_path | |
else | |
render :new, :error => "There was some validation error" | |
end | |
end | |
if params[:tip] | |
redirect_to congrats_path | |
end | |
if !params[:tip] and !params[:quote] and !params[:workout] | |
render :new, :errors => "you must add a workout, tip or quote." | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment