Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

Help with scaffold and act as tree

Question posted by: JackInDaBox (Newbie) on September 19th, 2007 04:32 PM
Hello,
newbie here...I have acts_as_tree working with active scaffold. My problem is that it lists parents and children in the scaffold. For instance the database has:

Code: ( text )
  1. id   | name     | parent_id |
  2. 1    |Animal    | null      |
  3. 2    |Cat       | 1         |
  4. 3    |Dog       | 1         |
  5. 4    |Siamese   | 2         |
  6. 5    |Collie    | 3         |


when it displays in active scaffold it lists it like:
Code: ( text )
  1. ---------
  2. |Animal   |
  3. |cat      |
  4. |Dog      |
  5. |Siamese  |
  6. |collie   |
  7.  ---------


What I want to do is see only where parent_id is nil but when i click the link 'Show Child' I want to bring up the children below the parent. such as:

Code: ( text )
  1. ------------------
  2. |Animal            |
  3. |   |cat        |  |
  4. |   |Dog        |  |
  5.  ------------------

I got the link for the child to work with:
Code: ( text )
  1. #in controller
  2. active_scaffold :category do |config|
  3.     config.columns =[ :name ]
  4.     config.nested.add_link("'Show Child'", [:children])
  5. end

But i need help to only display the parent at the start.

Thanks
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
modsaid's Avatar
modsaid
Newbie
1 Posts
May 4th, 2008
05:18 PM
#2

Re: Help with scaffold and act as tree
Hi Jack

try adding this method to the controller

def conditions_for_collection
"parent_id is null " unless params[:parent_model]
end

it should do the trick

Quote:
Originally Posted by JackInDaBox
Hello,
newbie here...I have acts_as_tree working with active scaffold. My problem is that it lists parents and children in the scaffold. For instance the database has:

Code: ( text )
  1. id   | name     | parent_id |
  2. 1    |Animal    | null      |
  3. 2    |Cat       | 1         |
  4. 3    |Dog       | 1         |
  5. 4    |Siamese   | 2         |
  6. 5    |Collie    | 3         |


when it displays in active scaffold it lists it like:
Code: ( text )
  1. ---------
  2. |Animal   |
  3. |cat      |
  4. |Dog      |
  5. |Siamese  |
  6. |collie   |
  7.  ---------


What I want to do is see only where parent_id is nil but when i click the link 'Show Child' I want to bring up the children below the parent. such as:

Code: ( text )
  1. ------------------
  2. |Animal            |
  3. |   |cat        |  |
  4. |   |Dog        |  |
  5.  ------------------

I got the link for the child to work with:
Code: ( text )
  1. #in controller
  2. active_scaffold :category do |config|
  3.     config.columns =[ :name ]
  4.     config.nested.add_link("'Show Child'", [:children])
  5. end

But i need help to only display the parent at the start.

Thanks

Reply
Reply
Not the answer you were looking for? Post your question . . .
170,098 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Top Ruby / Rails Forum Contributors