mwalsh2020 / lsat-cracked

1 stars 0 forks source link

93 new intro quiz #155

Closed jamiesonreinhard closed 3 years ago

jamiesonreinhard commented 3 years ago

Closes #93

Reviewed mentor branch and implemented changes with several commits on this branch.

Next step is to render a quiz report upon submitting the intro-quiz on the homepage. I'm trying to wrap my head around this logic.

@caioertai -- will I need to create a new Guest::Sessions controller for this? See attached routing error. Screen Shot 2021-02-02 at 8 28 39 AM

caioertai commented 3 years ago

Yes, @jamiesonreinhard. I stopped at the router level, but it needs the controller.

It's the same old flow of Router, Controller, View.

caioertai commented 3 years ago

The job of this controller action will be to take the parameters from the form (the users answers to the quiz) and initialize the session with them in order for the report to be rendered.

You can check this controller for reference: Course::Quiz::SessionsController.

jamiesonreinhard commented 3 years ago

The job of this controller action will be to take the parameters from the form (the users answers to the quiz) and initialize the session with them in order for the report to be rendered.

You can check this controller for reference: Course::Quiz::SessionsController.

I think I'm on the right track here but maybe you can give me a hint... not sure how to intantiate an instance of a quiz properly here in the highlighted line. @caioertai

Screen Shot 2021-02-02 at 10 37 07 AM

caioertai commented 3 years ago

So. 2 things:

  1. You should use #build from the quiz builder, for consistency. #new_quiz should have been a private method. My bad there.
  2. Once the quiz builder returns you a quiz instance, you should get a quiz session from using Quiz#session. No need to instantiate it yourself.
caioertai commented 3 years ago

Ignore my second point. I just realized this only works for a new session. It might be a good idea to include the parameters on the method to make it better in the future

jamiesonreinhard commented 3 years ago

Got it. So now the quiz builder "build" method is breaking because it isn't receiving a "quizable" with params. The "quizable" should be the article in this case, right? So how can I pass the article from the homepage view, to the guest session controller, to the quiz builder?

caioertai commented 3 years ago

Alright. Let's rewind.

Here's the Course::Quiz::SessionsController#create

  def create
    @quiz = Quiz.find(params[:quiz_id])
    @quiz_session = Quiz::Session.new(quiz_session_params.merge(quiz: @quiz))

    authorize @quiz_session

    if @quiz_session.save
      redirect_to course_section_path(@quiz.quizable, anchor: "quiz")
    else
      @section = @quiz_session.quiz.quizable
      render "course/sections/show"
    end
  end

It needs an instance of a quiz, then it can pass it, along with the quiz session params to the session. For the the course action the quiz can be found via id, since it's persisted. In case of the guest section, we're going to need to build it again, and the way to build it is by using the QuizBuilder. You have the right idea using it, but you're not using its interface properly. Check the initialize: image

It needs a user, which is a current_user (a guest in this case), and a quizable (the article).

Indeed getting the article in the create is not possible right now since we don't have the article being sent as an argument or present in the body of the POST. We have 2 ways for solving this (3 with a hack):

  1. Add the resources :article as part of the post route (and change the form accordingly to include quiz.quizable). So the form build would become: [:guest, quiz_session.quiz.quizable, quiz_session].
  2. Do not change the form in any way and just get the @quizable in the controller as Article.first.
  3. Add a f.input :article_id, as: :hidden, value: quiz_session.quiz.quizable.id to the form.
jamiesonreinhard commented 3 years ago

Thanks for the explanation there. That makes sense now. I think I'm getting closer, let me know if this looks correct.

Screen Shot 2021-02-02 at 1 13 28 PM

This is the new error related to not finding a quiz question:

Screen Shot 2021-02-02 at 1 10 55 PM

caioertai commented 3 years ago

Yeah.... this one might be tricky. Can we have a pair session tomorrow about it, @jamiesonreinhard? I'm concerned and involves some other things I wasn't planning on.

caioertai commented 3 years ago

I don't have a single meeting tomorrow, so any time should be fine.

jamiesonreinhard commented 3 years ago

Ok great, how about 11am CT?

caioertai commented 3 years ago

Ok great, how about 11am CT?

Perfect.

jamiesonreinhard commented 3 years ago

@caioertai I worked a little bit on styling the intro quiz report show page, as well as the actual quiz on the homepage. I made the quiz expandable/collapsible which I think looks okay - I think it could use more styling in the future but works well for now. Let me know what you think.

jamiesonreinhard commented 3 years ago

@caioertai also, there are two bugs I found.

  1. When you're on the show page for the quiz report and you try to refresh, it breaks. Screen Shot 2021-02-09 at 3 47 11 PM
  2. If you leave any of the quiz questions blank on the intro quiz, it breaks. Screen Shot 2021-02-09 at 3 51 27 PM
caioertai commented 3 years ago

@caioertai also, there is one bug. When you're on the show page for the quiz report and you try to refresh, it breaks. Thoughts on a workaround for that? Screen Shot 2021-02-09 at 3 47 11 PM

Well... we can leave this for another time. We could save the quiz results in the user session (cookies), so if the user refreshes we check for a saved quiz session in the session (yeah... sounds weird, I know)...

caioertai commented 3 years ago

Btw. It's not a bug. There IS no quiz session to show unless it comes straight from the form the user submits. So it only lasts one request. It's like this:

So what we could do on a GET is check the user cookies for a quiz session.