I am trying to make an app with Rails 4, using Simple Form.
I have three models - Project, Scope and Participant.
Scope belongs to Project and accepts nested attributes for participant. Participant belongs to Scope and accepts nested attributes for scope.
In my participant view, I have a partial form.
In my scope model, I have a boolean attribute asking users if they want participants in their project. If the answer is true, then I reveal the participants partial form and ask the questions in the participants model.
In my javascripts directory, I have a form helpers file, in which I use JS to hide the participants form until the answer in the scope form (about wanting participants is true), in which case, the partial is displayed. One of the questions in that form is whether the user wants money. I use money-rails to monetise that attribute.
My code all worked fine, except for that if you wanted to edit the project after it was created, you had to unclick the scope boolean question (asking if you wanted participants) and reclick it, in order to show the participants form. That's why I amended my JS form helper to check if that boolean was true before the change event.
As a result of that change, now, when I create a project, when the scope attribute (asking if you want participants) is false, I can't save a new project because I get an error saying the money object in participants cannot be incomplete. I don't understand how this has become a necessary input (in all projects). I have a validation in my money initialiser, which validates the numerically of the attribute, but it should be allowed to be nil.
I updated my participant.rb model to allow null
However, when I test this with a new project, I get an error that says: ERROR: null value in column "participation_cost_pennies" violates not-null constraint
Does anyone know how to fix this?
Thank you,