Skip to content

Instantly share code, notes, and snippets.

@ruprict
Created January 9, 2015 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruprict/42d2620370cea4a7d44c to your computer and use it in GitHub Desktop.
Save ruprict/42d2620370cea4a7d44c to your computer and use it in GitHub Desktop.
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