Created
January 9, 2015 13:40
-
-
Save ruprict/42d2620370cea4a7d44c to your computer and use it in GitHub Desktop.
This file contains 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 add_missing_answers | |
answer_count = @check_in.check_in_answers.length | |
return if answer_count >= 4 | |
answers_to_add = 4 - answer_count | |
answers_to_add.times do | |
@check_in.check_in_answers.build | |
end | |
end | |
def render obj | |
return super if params[:action] == 'destroy' | |
@check_in ||= check_in_by_id || new_check_in | |
@check_in.valid? if validate_check_in? | |
add_missing_answers | |
super | |
end | |
def validate_check_in? | |
params[:check_in] || !@check_in.new_record? | |
end | |
def check_in_by_id | |
CheckIn.find(params[:id]) if params[:id].present? | |
end | |
def new_check_in | |
CheckIn.new(params[:check_in]) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment