Skip to content

Commit

Permalink
Add a flag to user in attempts model to make it optional
Browse files Browse the repository at this point in the history
In rails 5, `belongs_to` adds the required validation by default with
it. Make it optional so that non-logged in users can also take the
survey.
  • Loading branch information
snkshukla committed Oct 3, 2019
1 parent 8ae73c1 commit e66c454
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/models/rapidfire/attempt.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
module Rapidfire
class Attempt < ActiveRecord::Base
belongs_to :survey
belongs_to :user, polymorphic: true
has_many :answers, inverse_of: :attempt, autosave: true

if Rails::VERSION::MAJOR >= 5
belongs_to :user, polymorphic: true, optional: true
else
belongs_to :user, polymorphic: true
end
end
end

0 comments on commit e66c454

Please sign in to comment.