New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SJ - Redo Jtm add form func to org #1116
SJ - Redo Jtm add form func to org #1116
Conversation
@questionnaire = Questionnaire.new(questionnaire_params) | ||
@submission = Submission.new | ||
@submission.questionnaire_responses.build | ||
respond_to do |format| | ||
format.js | ||
if @questionnaire.valid? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BigChiefSmidgeums What would happen here if the questionnaire is not valid? Should it flash an error instead, maybe something like
unless @questionnaire.valid?
flash[:alert] = "Questionnaire invalid"
end
submissions = {} | ||
if has_incomplete_service | ||
submissions[:Services] = [] | ||
ssr.line_items.includes(:service).map(&:service).each do |service| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Service.where(id: ssr.line_items.pluck(:service_id)).distinct.each
would be a bit more efficient. Instead of hitting the database n services
times, it hits it once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kyle-glick the use of .includes(:services) means that the services are eager loaded with the line items. Tested in console, this creates only two queries. One to load all the line items, and one to load all the services. There is no query per service.
.col-sm-12.text-center.no-padding | ||
= index+1 | ||
= item.item_options.index(item_option)+1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably a bit more inefficient than using each_with_index
because it will need to loop through item_options
for each option. Is there a specific reason to change it?
Reverts the original revert, effectively a "redo."
Reverts #1110