Forum: Ruby on Rails Category/subcategory CRUD

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A4d2b45412a6be67c164884b3b291b82?d=identicon&s=25 Nando Vieira (fnando)
on 2005-12-21 20:40
Hello there! This is my first post! ;)
I'm starting on ruby on rails, so I have many doubts about it!

I'm trying to create a system that uses categories/subcategories.
I created a scaffold for a table that has the following fields:

- id int(11)
- name varchar(50)
- keyname varchar(50)
- visible enum('0','1') default '0'
- pid int(11)

The rows are added as:
1, Articles, articles, 1, 0
2, Ruby on Rails, rubyonrails, 1, 1
3, PHP, php, 1, 1
4, FAQ, faq, 1, 0
5, Question 1, q1, 1, 4
6, Question 2, q2, 1, 4

And so on....

The PID field denotes the parent category. So, I have a structure like:

Articles
-- Ruby on Rails
-- PHP
FAQ
-- Question 1
-- Question 2

My question is: I created a scaffold for CRUD the categories. How to add
a SELECT tag populated with all categories that doesn't has the parent
id (pid)?

I want something like:

NEW CATEGORY
----------------
Name: _________
Keyname: _________
[x] Turn this category visible
Parent category: [------------------]   <= combobox
                 [No parent category]
                 [Articles]
                 [FAQ]


Thanks!
This topic is locked and can not be replied to.