Connecting Tech Pros Worldwide Forums | Help | Site Map

Help with scaffold and act as tree

Newbie
 
Join Date: May 2007
Posts: 6
#1: Sep 19 '07
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:

Expand|Select|Wrap|Line Numbers
  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         |
  7.  
when it displays in active scaffold it lists it like:
Expand|Select|Wrap|Line Numbers
  1.  ---------
  2. |Animal   |
  3. |cat      |
  4. |Dog      |
  5. |Siamese  |
  6. |collie   |
  7.  ---------
  8.  
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:

Expand|Select|Wrap|Line Numbers
  1.  ------------------
  2. |Animal            |
  3. |   |cat        |  |
  4. |   |Dog        |  |
  5.  ------------------
  6.  
I got the link for the child to work with:
Expand|Select|Wrap|Line Numbers
  1. #in controller
  2. active_scaffold :category do |config|
  3.     config.columns =[ :name ]
  4.     config.nested.add_link("'Show Child'", [:children]) 
  5. end
  6.  
But i need help to only display the parent at the start.

Thanks

Newbie
 
Join Date: Dec 2006
Posts: 1
#2: May 4 '08

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:

Expand|Select|Wrap|Line Numbers
  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         |
  7.  
when it displays in active scaffold it lists it like:
Expand|Select|Wrap|Line Numbers
  1.  ---------
  2. |Animal   |
  3. |cat      |
  4. |Dog      |
  5. |Siamese  |
  6. |collie   |
  7.  ---------
  8.  
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:

Expand|Select|Wrap|Line Numbers
  1.  ------------------
  2. |Animal            |
  3. |   |cat        |  |
  4. |   |Dog        |  |
  5.  ------------------
  6.  
I got the link for the child to work with:
Expand|Select|Wrap|Line Numbers
  1. #in controller
  2. active_scaffold :category do |config|
  3.     config.columns =[ :name ]
  4.     config.nested.add_link("'Show Child'", [:children]) 
  5. end
  6.  
But i need help to only display the parent at the start.

Thanks

Reply