SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Feb 2007
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Red face multiple checkboxes to describe one model attribute?

    I'm a RoR newb looking to make a simple edit to a scaffolding form. I'm having trouble getting form helpers to do what I want with regard to checkboxes.

    I have a model object NewsItem that has an attribute called segment. A given NewsItem can have one or more segments, which I would like to represent as checkboxes.

    Once the form is submitted, the checked-off segments are then concatenated together as the segment attribute for that instance of NewsItem.

    That's what I want to make happen, but I can't figure out the syntax for describing this. Based on the way Rails operates, I would think there would be some kind of shorthand that lets a collection of checkboxes be automatically aggregated together to describe one attribute. Is that the case, or do I need to manually concatenate the values in the model?

    Thanks in advance for any help!

  2. #2
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What are segments? Are the segments in a different table? Is a segment a text? Do you have NewsItem has_many :segments? Do you enter the segments in a textarea and then check which ones you want? This is really important for us to know.

  3. #3
    SitePoint Member
    Join Date
    Feb 2007
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for responding. Through some hacking around, I've solved the problem I was having, but I'm going to post on a larger design issue that reared its head in the process of finding this fix.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •