Home>

I'm going to make 3-4 choices in Rails.
StackOverflow "Create a quiz app for Ruby on Rails. Passing id"
Implementing with reference to.

Error message

For reference above,
def mark
quizzes = Quiz.find (params [: tests])
@answers = []
quizzes.each do | q |
answers<<{quiz: q, right: q.right_answer? (params ["quiz # {q.id}"])}
end
end

I don't know where [: tests] came from in

.
Does quizzes store all the selected quiz data in an array?
Also, what are the errors?
Couldn't find Quiz without an ID

Tried

I did various things to reflect the id of the question that would have been selected in [: tests]
I can't ...

Supplemental information (FW/tool version etc.)

Please provide more detailed information here.

  • Answer # 1

      

    StackOverflow "Create a quiz app for Ruby on Rails. Passing id"
      Implementing with reference to.

    What about this? It may be better to put the URL of the site you are referring to.
    https://StackOverflow.com/questions/17322

      

    I couldn't do anything to reflect the id of the question that would have been selected in [: tests] ...

    That's right,@quizzes = Quiz.all.sample (5)will contain the ID of the quiz extracted.

    When you look at the source

    controller:quizzes = Quiz.find (params [: tests])

    view:<% = hidden_field_tag ​​"quiz []" ;, quiz.id%>

    params:
    # params =>{: quizzes =>[1,5,8,14,20],"quiz1"=>'quiz1 form input&apos ;,"quiz5"=>&apos ;quiz5 form input&apos ;,"quiz8"=>'quiz8 form input&apos ;,"quiz14"=>'quiz14 form input&apos ;,"quiz20"=>'quiz20 Form input'}

    and the parameter names used are different, so I can't say anything.
    I think you should use the parameter name that contains the ID of the quiz on the console screen.

    If you write the view in the same way as the reference page, you can get it withparams [: quiz].

Related articles