SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2005
    Location
    Eastbourne, UK
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Quick Q: How to add a blank category to Category.find_all?

    Hi,

    The app I'm currently building is my first attempt at a full RoR website. I've got most of my multi-level category system working how I would like (acts_as_nested_set is great!) but there is one little thing I've got stuck on:

    In my new category function I have the following code:

    Code:
    def new
        @category = Category.new
        @categories = Category.find_all
    end
    This works great for having a Category dropdown where I can select the new category's parent, however it doesn't let me create a new category as a root-level item.

    How can I add a blank (or equivalient root-level) item to the beginning of @categories?

    I know it's probably simple but I havn't seen any mention of this in tutorials or books so far so I'm sure others like me will find the answer useful.

    Thanks,
    Kev

  2. #2
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Location
    Norway
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try creating a category with parent 0.

  3. #3
    SitePoint Evangelist lirux's Avatar
    Join Date
    Jan 2001
    Location
    Lisboa : Portugal
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you could use options_from_collection_for_select and then manually wrap it with a select tag, so you can add extra options yourself..
    Duarte Carrilho da Graša
    RailsHelp.com: Searchable Rails reference
    CACA: Committee for the Annihilation of Complicated Acronyms


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
  •