Okay I’ll try and show you what errors I’m getting later.
For now let me try to explain the situation a bit more clearly
(apologies, I’m still learning, this is my first app and I’m mainly
doing it to learn rails, quite possibly I’m way off on what I’m doing).
I created a quiz scaffold and used devise to set up users.
When a user logs in, they have a dashboard with a link to ‘quiz’. This
goes to the index action of the quiz controller, which displays all of
the quizzes. I want to build the actual functionality into the quiz#show
action, which gets an individual quiz form.
However, the part I’m struggling to understand is this: They ‘answers’
to the quiz have to belong to the user, surely? I can’t have an ‘answer’
attribute on the quiz, because then each user would just be updating
this attribute belonging to quiz each time they submit something (by the
way, there is only 1 question on each quiz page).
So, I’ve set up the ‘answer’ attribute as part of the user. The idea is
that the user goes to the quiz/:id page, inputs their answer, this is
then sent using a put update request to edit the users ‘answer’
attribute and manipulate it/check it for correctness.
So my show.html.erb for quiz is something like:
<%= @quiz.title %>
<%= @quiz.question %>
<%= form_for(resource, as: resource_name, url:
registration_path(resource_name), html: { method: :put }) do |f| %>
<%= f.label :answer %>
<%= f.text_field :answer %>
<%= f.submit "Submit" %>
<% end %>
Does this make sense, or is this there a far easier way of doing it?
I appreciate the help! Thanks.
Joe