☒ I would start by having an attribute on the response that is tied to the user/student (user:belongs_to) and put a validation uniqueness scope on the response which scopes the user and questionnaire. This would limit the user for one response per questionnaire/exam. What other kind of functionality are you looking for?
A couple of thoughts,
when displaying out the answers when gathering the response, you could shuffle the array of answers so they do not appear in the same order for everyone.
the creator of the exam could mark an answer as correct on each question. when a response is submitted, a background job can be queued up to grade the questionnaire response.
A grading table which has user:belongs_to, questionnaire:belongs_to, and response:belongs_to along with grade could be created as a result. This would increase the performance of the application as it doesn't have to do the grading calculations every time.
Just some thoughts on weights... For the weights, I would recommend not trying to match 100%. It's not too difficult, but it's really annoying. So much front end validation to do and requiring the user to do some math to match up values to 100%. Instead, if you have 10 questions and you give them a weight of 50 each, then each question would be 10% of the total score. This will be much easier logic to handle. You could use a stimulus controller to add up each of the weight inputs and show a percentage value as you setup the questionnaire.
Hello David Kimura I try to rebuild this project after I want to integrate on my Start up like Exercise feature. why did you choose the json format for answer? when you created Responses Scaffold, Why important? I think json is for answers coming from APIs
Kam kara I chose json format since the structure and format of the responses are not a consistent structure. Basically, it makes it more simple to store the data. A questionnaire could have a few questions and then many answers or many questions and just a few answers each. If you were to create a table-based response, then you would need to almost mimic the structure of the questionnaire where you have a responses table which has many question_responses and the question responses has many answer_responses (since it could me multiple choice). Then you need to worry about the type of response for the answer where the some of them may be a boolean, string, or text and picking the correct type when storing the response.
I've followed these videos to make a questionnaire system and now I want to be able to export the results as a csv. I've watched the earlier video (EP 35), but can't get my head around how to go about this. What would be best?
Luke Scott I would make a Ruby class which took in the results of a questionnaire and format it in a way that you're wanting the CSV to look. So, you'd basically make an array with the first item in the array being an array of all of the headers. Then you'd loop through each response and put their response in the appropriate position in the array. From there, you can generate the CSV response and send a file to the client.
Tom Murdoch If a questionnaire has already received responses, then I would not recommend altering the questionnaire. I've seen this before and it caused so many problems where the first several responses has the old questionnaire in mind but no longer valid. While, as developers of the questionnaire feature, we would know how to navigate this "safely", but end users will always surprise you with what they'd do. The safest thing would be to recall a questionnaire and generate a copy of an existing one to then modify.
Hi David, thanks for the fast response! I do not wish to alter the questionnaire questions or associated answers. The questions/answers will never change in my particular case. I would however like the ability for the user to be able to edit their responses though. So they can go back and correct grammar and spelling if they need to in the future.
2) How do I make this questionnaire available for student and lecturer without having to write double code? The difference between the lecturer and student questionnaire is obviously the questions asked.
1. The response instance variable looks to be nil in the snippet which is why you probably cannot link to the response show page.
2. When are you trying to make the differentiation? Is it when pulling up a list of available questionnaires to take? If so, you could have an attribute on the questionnaire for the type of user. Something like "responder_type" and make it an enum. When listing out the questionnaires, you could query on this attribute depending on the actor (a lecturer or student).
A couple of thoughts,
Only thing I'd want to add would be different questions weights, but would only require an extra column to the questions table.
why did you choose the json format for answer? when you created Responses Scaffold, Why important?
I think json is for answers coming from APIs
1) How do I link to the response show page from questionnaire index page?
I tried
I got error
2) How do I make this questionnaire available for student and lecturer without having to write double code? The difference between the lecturer and student questionnaire is obviously the questions asked.
I can share my github link for help.
2. When are you trying to make the differentiation? Is it when pulling up a list of available questionnaires to take? If so, you could have an attribute on the questionnaire for the type of user. Something like "responder_type" and make it an enum. When listing out the questionnaires, you could query on this attribute depending on the actor (a lecturer or student).