On Oct 7, 2014, at 12:13 PM, Joseph Wilks <li...@ruby-forum.com> wrote:

> 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.
> 


You probably want the answer to belong_to both the user and the quiz.


> So my show.html.erb for quiz is something like:
> 
> <h1><%= @quiz.title %></h1>
> 
> <p>
>  <%= @quiz.question %>
> </p>
> 
> <%= form_for(resource, as: resource_name, url: 
> registration_path(resource_name), html: { method: :put }) do |f| %>
>  <div><%= f.label :answer %>
>  <%= f.text_field :answer %> </div>
>    <div><%= f.submit "Submit" %></div>
> <% end %>
> 
> 


"resource" is probably something you copied from an example (or the docs). 
You're supposed to put the actual object there, like @answer (assuming you have 
created the @answer object as an instance variable in your controller)

the url: is going to be a path correlated to the answer routes, which you will 
define in your routes file. You can use rake routes to figure out what the 
named routes are. 




> Does this make sense, or is this there a far easier way of doing it?
> 
> I appreciate the help! Thanks.
> 
> Joe

----

Jason Fleetwood-Boldt
t...@datatravels.com
http://www.jasonfleetwoodboldt.com/writing

All material © Jason Fleetwood-Boldt 2014. Public conversations may be turned 
into blog posts (original poster information will be made anonymous). Email 
ja...@datatravels.com with questions/concerns about this.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/D3E608E4-1AAF-4BBA-8E51-177ECF639902%40datatravels.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to