0

I have next models:

class Student < ApplicationRecord
    has_many :special_offers_participants
end

class SpecialOffersParticipant < ApplicationRecord
    belongs_to :special_offer
    belongs_to :student
end

class SpecialOffer < ApplicationRecord
    has_many :special_offers_participants
end

I need to create registration form for student that depending on session attributes will either have special offer acceptance or decline radio buttons, either not (session can have special_offer_id). It’s obvious for me to acomplish this using nested form attributes, but the form should have a question: Do you accept special offer and radio buttons: Yes/No. Besides that the answer to this question should be required.

Can you provide me any direction to complete the solution?

1 Answers1

0
class Student < ApplicationRecord
    has_many :offers
    has_many :promotions, through: :offers
end

class Offer < ApplicationRecord
    belongs_to :student
    belongs_to :promotion
end

class Promotion < ApplicationRecord
end 
Fabrizio Bertoglio
  • 5,890
  • 4
  • 16
  • 57
  • there're several special offers that're offered (i.e. get a reward for exam completion, etc) to the studens and those are the same. So I need a pivot table to understand what offers are applied to the student – Oleg Boris Aug 24 '18 at 08:12
  • @OlegBoris ok.. still I don't have a clear picture ... but I notice that your `SpecialOffersParticipant` is just a join table between `Student` and `SpecialOffer`. We use join tables only with `has_and_belongs_to_many` associations while the alternative is the `has_many` through another `has_many` association Also I would avoid those long class names because they make the whole concept more complex I updated my answer but still may not be what you are searching for ... because I have not clear idea – Fabrizio Bertoglio Aug 24 '18 at 08:40
  • special offers participant in fact is included in module. I've made simplification here. it's named `SpecialOffers::Participant` in fact. The system I'm creating is quite tricky. The landing page for users are shown with split gem, so they can get different landings. They get session variable there, that put special_offer.id to user's session. On the registration page they depending on session are getting special offer fields. The problem is that they have to express their desire to participate in special offer by selecting of radio buttons and that should be required field – Oleg Boris Aug 24 '18 at 15:58