Hi, how can I use checkbox in a form to show all customers from table customers, Course Users Customers ========= ========= ============user_id customer_id Customer_name I would like to select customers from the checkbox list, then add to the course table only users of the selected customers. thanks dani -- 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-/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.
On Sep 25, 2011, at 1:39 PM, Dani Dani wrote:> Hi, > how can I use checkbox in a form to show all customers from table > customers, > > Course Users Customers > ========= ========= ============> user_id customer_id Customer_name > > I would like to select customers from the checkbox list, then add to the > course table only users of the selected customers.What does the relationship look like between Course and Customer? Is there an Enrollment object sitting between them? One way might be to have a form_for @course on your Customers#index page, and a submission of that to the CoursesController would build a new Enrollment for each submitted Customer on that Course. Walter -- 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.
Walter Davis wrote in post #1023809:> > What does the relationship look like between Course and Customer? Is > there an Enrollment object sitting between them? > > One way might be to have a form_for @course on your Customers#index > page, and a submission of that to the CoursesController would build a > new Enrollment for each submitted Customer on that Course. > > WalterHi Walter, Thank you for your response. There is no direct releationship between customers and course tables. Could you please be more specific in regard to:> One way might be to have a form_for @course on your Customers#index > page, and a submission of that to the CoursesController would build a > new Enrollment for each submitted Customer on that Course.I just want to display all customers for a selection (checkbox style). Thanks Dani -- 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-/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.
On Sep 28, 2011, at 4:13 AM, Dani Dani wrote:> Walter Davis wrote in post #1023809: >> >> What does the relationship look like between Course and Customer? Is >> there an Enrollment object sitting between them? >> >> One way might be to have a form_for @course on your Customers#index >> page, and a submission of that to the CoursesController would build a >> new Enrollment for each submitted Customer on that Course. >> >> Walter > > Hi Walter, > Thank you for your response. > > There is no direct releationship between customers and course tables.Then in order to have such a relationship (or the inverse -- a lack of relationship) between any given Course and any given Customer, you will need to store that graph somewhere. I would make a new Enrollment model, and give it the following attributes: customer_id course_id You could add other decorations to it if you like, certainly the default timestamps could be useful, but you could also add a column for how much the customer paid, any other details about this transaction you need to store and retrieve later. Then, in the model file, you would add belongs_to :course belongs_to :customer And in your Course and Customer models, you would add the same declaration in each: has_many :enrollments And the specific declaration for each: has_many :courses, :through => :enrollment (in Customer) has_many :customers, :through => :enrollment (in Course)> > Could you please be more specific in regard to: >> One way might be to have a form_for @course on your Customers#index >> page, and a submission of that to the CoursesController would build a >> new Enrollment for each submitted Customer on that Course. > > I just want to display all customers for a selection (checkbox style).The rest is pretty easy. If you have a form for a course, you can gather all of the possible attendees for that course using @customers = Customer.all in your CoursesController. The relationship will take care of everything else. In your enrollment form view, you would then iterate over those, and build your checkboxes (I''ve left out all the html and erb tags for clarity): form_for @course do |f| @customers.each do |customer| f.check_box [:customers, customer], @course.customers.include?(customer) f.label customer.name, [:customers, customer] end f.submit end That''s off the top of my head, but it should point you in a working direction. Walter> > Thanks > Dani > > -- > 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-/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. >-- 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.
Thank you very much walter for your time and efforts. I''ll try this. Dani -- 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-/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.