473,419 Members | 1,594 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,419 software developers and data experts.

Help with scaffold and act as tree

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
1 6491
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

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

Similar topics

0
by: Tree menu using XML | last post by:
I have one XML file that has nodes and sub node and each and every node has the attribute call visible if its value is true then diplay this node else don't display thid node, but this condition i...
4
by: Tarique Jawed | last post by:
Alright I needed some help regarding a removal of a binary search tree. Yes its for a class, and yes I have tried working on it on my own, so no patronizing please. I have most of the code working,...
66
by: genestarwing | last post by:
QUESTION: Write a program that opens and read a text file and records how many times each word occurs in the file. Use a binary search tree modified to store both a word and the number of times it...
5
gekko3558
by: gekko3558 | last post by:
I am writing a simple binary search tree (nodes are int nodes) with a BSTNode class and a BST class. I have followed the instructions from my C++ book, and now I am trying to get a remove method...
0
by: resurgentnaveen | last post by:
Hi , I am trying to use Active Scaffold in my project and i need this template overriding feature of Active Scaffold. I am following the instructions on the link...
4
by: Dr Nic | last post by:
ANN: JavaScript Project Generator WWW: http://newjs.rubyforge.org Generates a scaffold for a new JavaScript project, with in-built test suite (using prototypejs's wonderful unittest.js). See...
8
by: slizorn | last post by:
Hi guys, I have this coding that I wanted to try out. Basically this is meant to be done in Java as practice for the Topic trees in data structures and algorithms. I have recently learned C++ on...
2
by: slizorn | last post by:
hi guys, i need to make a tree traversal algorithm that would help me search the tree.. basically i need to read in a text file... shown below H H,E,L E,B,F B,A,C A,null,null c,null,D
2
by: slizorn | last post by:
hi guys, i need to make a tree traversal algorithm that would help me search the tree.. creating a method to search a tree to find the position of node and to return its pointer value basically i...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.