Hi, guys. I''m new to Rails and right now I''m trying to write simple test system. The thing is that I don''t know how get data from multiple tables and put the into one select box. Here is my db scheme and what I want to do. -> http://mitkokostov.info/images/screenshot.jpg Thanks in advance, Mitko Kostov -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Thu, 2008-07-17 at 00:32 +0200, Mitko Kostov wrote:> Hi, guys. > > I''m new to Rails and right now I''m trying to write simple test system. > The thing is that I don''t know how get data from multiple tables and > put the into one select box. Here is my db scheme and what I want to do. > -> http://mitkokostov.info/images/screenshot.jpg >---- get a better concept first... Class Question has_many :answers :id integer primary_key :answer_id integer, foreign_key # this is the correct answer id :question :string Class Answer belongs_to :question :id integer primary_key :question_id integer :answer :string @answers = Answer.find(:all, :conditions => ["question_id = ?", @question]) <%= options = [[''Select Answer'', '''']] + @answers.sort { |a,b| a.answer <=> b.answer }.collect { |ans| [ans.answer, ans.id] } select ''quiz'', ''answer_id'', options %> Craig --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> > @answers = Answer.find(:all, :conditions => ["question_id = ?", > @question]) > > <%= options = [[''Select Answer'', '''']] + @answers.sort { |a,b| a.answer > <=> b.answer }.collect { > |ans| [ans.answer, ans.id] } > select ''quiz'', ''answer_id'', options %> > > CraigThanks very much, but I want to have suggestions, not only questions and answers. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Thu, 2008-07-17 at 00:54 +0200, Mitko Kostov wrote:> > > > @answers = Answer.find(:all, :conditions => ["question_id = ?", > > @question]) > > > > <%= options = [[''Select Answer'', '''']] + @answers.sort { |a,b| a.answer > > <=> b.answer }.collect { > > |ans| [ans.answer, ans.id] } > > select ''quiz'', ''answer_id'', options %> > > > > Craig > > Thanks very much, but I want to have suggestions, not only questions and > answers.---- either I don''t understand your question or you didn''t understand my answer. The answers file would provide multiple choices for each question but only 1 correct answer for each question. Craig --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Craig White wrote:> On Thu, 2008-07-17 at 00:54 +0200, Mitko Kostov wrote: >> >> Thanks very much, but I want to have suggestions, not only questions and >> answers. > ---- > either I don''t understand your question or you didn''t understand my > answer. The answers file would provide multiple choices for each > question but only 1 correct answer for each question. > > Craigfor example I have one question, answer to that question and multiple suggestions, but incorrect. The questions in my DB will be very different, so it will be inappropriate to use other answers as suggestions to a question. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Thu, 2008-07-17 at 01:08 +0200, Mitko Kostov wrote:> Craig White wrote: > > On Thu, 2008-07-17 at 00:54 +0200, Mitko Kostov wrote: > >> > >> Thanks very much, but I want to have suggestions, not only questions and > >> answers. > > ---- > > either I don''t understand your question or you didn''t understand my > > answer. The answers file would provide multiple choices for each > > question but only 1 correct answer for each question. > > > > Craig > > for example I have one question, answer to that question and multiple > suggestions, but incorrect. The questions in my DB will be very > different, so it will be inappropriate to use other answers as > suggestions to a question.---- re-read my initial reply - it is the best solution I think. Craig --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> re-read my initial reply - it is the best solution I think. > > CraigI read it like four times. For example I have: 1. What is the fastest car ? - Answer -> Bugatti 2. How many minutes are in one hour -> 60 3. What is the first grafical browser -> Mosaic With your approich when I get question number 1. What is the fastest car ? the answers in the select box will be Bugatti, 60 and Mosaic and it will be obvious that the correct answer is Bugatti. Because of this I add third table which will contain similar, but incorrect answers for every question and I named it suggestions. So my purpose it to get question and render its correct answer and some "suggestions" ( through question_id ). -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Craig White
2008-Jul-16 23:35 UTC
Re: ****[Rails] Re: ****[Rails] Select box for multiple models
On Thu, 2008-07-17 at 01:26 +0200, Mitko Kostov wrote:> > re-read my initial reply - it is the best solution I think. > > > > Craig > I read it like four times. > > For example I have: > > 1. What is the fastest car ? - Answer -> Bugatti > 2. How many minutes are in one hour -> 60 > 3. What is the first grafical browser -> Mosaic > > With your approich when I get question number 1. What is the fastest car > ? the answers in the select box will be Bugatti, 60 and Mosaic and it > will be obvious that the correct answer is Bugatti. Because of this I > add third table which will contain similar, but incorrect answers for > every question and I named it suggestions. So my purpose it to get > question and render its correct answer and some "suggestions" ( through > question_id ).---- no - because if you look, I had ''question_id'' for each answer, so there could be as many/few answers associated with each specific question and only 1 correct answer for each question. Craig --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mitko Kostov
2008-Jul-16 23:39 UTC
Re: ****[Rails] Re: ****[Rails] Select box for multiple mode
Sorry, Craig. I''m so stupid. I really didn''t fully understand your way. Thanks very much. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---