By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,831 Members | 1,031 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,831 IT Pros & Developers. It's quick & easy.

Help with scaffold and act as tree

P: 6
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
Sep 19 '07 #1
Share this Question
Share on Google+
1 Reply


P: 1
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

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
May 4 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.