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@googlegroups.com.
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.

Search Discussions

  • Walter Lee Davis at Sep 26, 2011 at 2:19 pm

    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@googlegroups.com.
    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.
  • Dani Dani at Sep 28, 2011 at 8:13 am

    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.

    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@googlegroups.com.
    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.
  • Walter Lee Davis at Sep 28, 2011 at 12:31 pm

    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@googlegroups.com.
    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@googlegroups.com.
    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.
  • Dani Dani at Oct 2, 2011 at 1:32 pm
    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@googlegroups.com.
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedSep 25, '11 at 5:39p
activeOct 2, '11 at 1:32p
posts5
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Dani Dani: 3 posts Walter Lee Davis: 2 posts

People

Translate

site design / logo © 2021 Grokbase