Skip to content

Instantly share code, notes, and snippets.

@robyurkowski
Created January 8, 2012 03:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save robyurkowski/1576990 to your computer and use it in GitHub Desktop.
Save robyurkowski/1576990 to your computer and use it in GitHub Desktop.
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