Smoq
2010-May-23 16:52 UTC
Questionairee''s questions - how to show all user''s answers? How to update database with ALL user''s answers?
I am using RoR 2.3.5. I would like to have list of questions with three possible answers. After having copleted a test I would like to update the database with user''s answers. At the bottom of the page I would also like to list all selected answers for the user. In a table "answers" I have columns: question, a1, a2, a3 (these columns are answers to the question), a_u (user''s answer), a_ok (correct answer). Below I have pasted the view that I am using for listing questions. But I have no idea how to list ALL answers at the bottom of the page (now I know how to show only one answer). And how (in the most effective way) to update the column "a_u" wtith ALL user''s answers? Could you help me? #-----------------------------------------------------index.htm.erb begin------------------------------------------------------------------ <h1>Listing answers</h1> <% @answers.each do |answer| %> <form > <!-- action = "\answers\selected" to gowno nie chce dzialac --> <td><%=h answer.question %></td> <input type="radio" name="answer1" value= <%=answer.a1%> /> <%=h answer.a1 %> <input type="radio" name="answer1" value= <%=answer.a2%> /> <%=h answer.a2 %> <input type="radio" name="answer1" value= <%=answer.a3%> /> <%=h answer.a3 %> <input type="submit"/> </form> <% end %> <br/> You selected <%= @data11 %> #-----------------------------------------------------index.htm.erb end------------------------------------------------------------------ In answers_controller I have included: @data11 = params[:answer1] -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Michael Pavling
2010-May-23 20:55 UTC
Re: Questionairee''s questions - how to show all user''s answers? How to update database with ALL user''s answers?
On 23 May 2010 17:52, Smoq <smoqquu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> In a table "answers" I have columns: question, a1, a2, a3 (these > columns are answers to the question), > a_u (user''s answer), a_ok (correct answer). Below I have pasted the > view that I am using for listing questions.Surely you have a "Question" model, which has the question text, and the three choices for answers (or even a "Choice" model, with a "Question :has_may Choices" relationship...), and in the "Answer" model you just store the question_id and the choice (or choice_id).> But I have no idea how to list ALL answers at the bottom of the page > (now I know how to show only one answer). And how (in the most > effective way) to update the column "a_u" wtith ALL user''s answers?For every question the user completes you have an Answer record (created when they answer a question, or updated if they''re allowed to edit), so users have many answers, and you can iterate to display all wherever you wish.> Could you help me? > > > #-----------------------------------------------------index.htm.erb > begin------------------------------------------------------------------ > <h1>Listing answers</h1> > > <% @answers.each do |answer| %> > <form > <!-- action = "\answers\selected" to gowno nie chce > dzialac --> > <td><%=h answer.question %></td> > <input type="radio" name="answer1" value= <%=answer.a1%> /> <%=h > answer.a1 %> > <input type="radio" name="answer1" value= <%=answer.a2%> /> <%=h > answer.a2 %> > <input type="radio" name="answer1" value= <%=answer.a3%> /> <%=h > answer.a3 %> > <input type="submit"/> > </form> > > <% end %> > <br/> > > You selected <%= @data11 %> > #-----------------------------------------------------index.htm.erb > end------------------------------------------------------------------ > > In answers_controller I have included: > > @data11 = params[:answer1] > > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Smoq
2010-May-24 06:42 UTC
Re: Questionairee''s questions - how to show all user''s answers? How to update database with ALL user''s answers?
On 23 Maj, 22:55, Michael Pavling <pavl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 23 May 2010 17:52, Smoq <smoq...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > In a table "answers" I have columns: question, a1, a2, a3 (these > > columns are answers to the question), > > a_u (user''s answer), a_ok (correct answer). Below I have pasted the > > view that I am using for listingquestions. > > Surely you have a "Question" model, which has the question text, and > the three choices for answers (or even a "Choice" model, with a > "Question :has_may Choices" relationship...), and in the "Answer" > model you just store the question_id and the choice (or choice_id). > > > But I have no idea how to list ALL answers at the bottom of the page > > (now I know how to show only one answer). And how (in the most > > effective way) to update the column "a_u" wtith ALL user''s answers? > > For every question the user completes you have an Answer record > (created when they answer a question, or updated if they''re allowed to > edit), so users have many answers, and you can iterate to display all > wherever you wish. > > > > > Could you help me? > > > #-----------------------------------------------------index.htm.erb > > begin------------------------------------------------------------------ > > <h1>Listing answers</h1> > > > <% @answers.each do |answer| %> > > <form > <!-- action = "\answers\selected" to gowno nie chce > > dzialac --> > > <td><%=h answer.question %></td> > > <input type="radio" name="answer1" value= <%=answer.a1%> /> <%=h > > answer.a1 %> > > <input type="radio" name="answer1" value= <%=answer.a2%> /> <%=h > > answer.a2 %> > > <input type="radio" name="answer1" value= <%=answer.a3%> /> <%=h > > answer.a3 %> > > <input type="submit"/> > > </form> > > > <% end %> > > <br/> > > > You selected <%= @data11 %> > > #-----------------------------------------------------index.htm.erb > > end------------------------------------------------------------------ > > > In answers_controller I have included: > > > @data11 = params[:answer1] > > > -- > > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. >Hi, Could you let me know what shuld be included in controller to list on the page ALL user''s answers? I also think that the view should be modified to show ALL user''s answers - but I have no idea how it should be changed. Could you modify it? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
pavling
2010-May-24 07:41 UTC
Re: Re: Questionairee''s questions - how to show all user''s answers? How to update database with ALL user''s answers?
On 24 May 2010 07:42, Smoq <smoqquu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Could you let me know what shuld be included in controller to list on > the page ALL user''s answers?You could populate a variable with the results of a find of the user''s answers, or just have a variable for the user and access "@user.questions" in the view.> I also think that the view should be > modified to show ALL user''s answers - but I have no idea how it should > be changed. Could you modify it?Are you asking me to *do* your work for you for free?! -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Smoq
2010-May-24 09:43 UTC
Re: Questionairee''s questions - how to show all user''s answers? How to update database with ALL user''s answers?
On 24 Maj, 09:41, pavling <pavl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 24 May 2010 07:42, Smoq <smoq...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Could you let me know what shuld be included in controller to list on > > the page ALL user''s answers? > > You could populate a variable with the results of a find of the user''s > answers, or just have a variable for the user and access > "@user.questions" in the view. > > > I also think that the view should be > > modified to show ALL user''s answers - but I have no idea how it should > > be changed. Could you modify it? > > Are you asking me to *do* your work for you for free?! > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.orgDo you suggest that I shuld pay you for the answer? :). I am learnig RoR and I don''t know how to solve the problem - it is not my work BTW. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
pepe
2010-May-24 12:51 UTC
Re: Questionairee''s questions - how to show all user''s answers? How to update database with ALL user''s answers?
If I were you I would buy a book or find info on the web and study how activerecord associations work. That will most likely clear all your questions and help you solve the problem. The examples I''ve read in any of the books I have are very clear. Good books: Agile Web Development with Rails and The Rails Way. Good luck. On May 24, 5:43 am, Smoq <smoq...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 24 Maj, 09:41, pavling <pavl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > On 24 May 2010 07:42, Smoq <smoq...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Could you let me know what shuld be included in controller to list on > > > the page ALL user''s answers? > > > You could populate a variable with the results of a find of the user''s > > answers, or just have a variable for the user and access > > "@user.questions" in the view. > > > > I also think that the view should be > > > modified to show ALL user''s answers - but I have no idea how it should > > > be changed. Could you modify it? > > > Are you asking me to *do* your work for you for free?! > > > -- > > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > Do you suggest that I shuld pay you for the answer? :). I am learnig > RoR and I don''t know how to solve the problem - it is not my work BTW. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.