similar to: Using custom routes to handle new nested resources

Displaying 20 results from an estimated 30000 matches similar to: "Using custom routes to handle new nested resources"

2009 Mar 08
2
RESTful nested resources and polymorphism?
With ref to my previous post: http://www.ruby-forum.com/topic/180356 I am now able to access items from topics controller. However, now I need to add sub-item e.g.: An item itself could have many sub-items. So my items model is like: class Item < ActiveRecord::Base validates_uniqueness_of :title, :scope => [:topic_id] validates_presence_of :topic_id, :title, :owner, :position
2006 Mar 24
6
Should counter_cache fields be saved in the database?
As far as I can tell, the counter_cache option on a belongs_to model doesn''t actually save anything in the database. For example, I have the following models: class Parent < ActiveRecord::Base has_many :children, :conditions => "deleted_at IS NULL" end class Child < ActiveRecord::Base belongs_to :parent, :counter_cache => true end With the following
2008 Jan 02
1
wants to get all parents with no children, etc
To all: hi, i have implemented the associations in my models so i have a Parent model that has many Children model but i need to get a list of Parents that do not have children or Parents that have just 2 children or Parents that have children whose name is ''James'', or ''Sarah'', or ''Betty'' or Parents whose children do not have names like
2006 Jul 13
1
How to create a child from a parent
Hi i am trying to figure out what is the best way to do this very basic thing: lets say i have two tables: one with parents and one with children. there is a one to many relation between them. I scaffolded the parents tabel and i can open each parent. Now i want to add a link to the ''show'' view which will create a new child record. In the model i defined the has_many and
2006 Mar 21
5
Order records based on number of children
Let''s say I have simple schema with two tables. The models are defined like the folllowing: class Parent < ActiveRecord::Base has_many :children end class Child < ActiveRecord::Base belongs_to :parent end Simple has_many relationship. Is there any way to order the results of a Parent.find_all by the number of children the parent has? I can sort with sorted_parents =
2006 Jan 05
2
Confused...
Ok, So, I''ve got two data tables associated through a foreign key. class Child < ActiveRecord::Base belongs_to :parent, :class => Parent, :foreign_key => "parent_id" # also has attr1, attr2 end class Parent < ActiveRecord::Base has_many :children, :class => Child, :foreign_key => "parent_id" end So, I''m trying to build the new/edit
2006 Feb 23
3
has_many: inserting children when inserting parent
disclaimer: am in the midst of my first ruby/rails project I have a situation where I want several child records to be created when a new parent record is created. The following represents my first stab at coding it, am I on the right track? Here is the model: parents ---------- id name children ---------- id parent_id name class Parent < ActiveRecord::Base has_many: children end
2005 Sep 23
6
problem with acts_as_tree
Hi, I''m using the latest gem version of rails under MacOS Tiger. I was trying to use acts_as_tree as described in the rails book. So I have something like: class Category < ActiveRecord::Base acts_as_tree :order => "title" end create table categories ( id int not null auto_increment, title
2006 Sep 13
1
Eager loading with acts_as_tree
So I have a model that acts_as_tree and I run a method on a collection of all of these records. This method walks the tree and fetches the parent/children, etc. This results in many, many duplicate SQL queries to be executed. Is there a way to eagerly load all of these models? Something along the lines of: Model.find(:all, :include => [:children, :parent]) If I execute the above statement, I
2006 Jun 16
1
sortable acts_as_tree with heirarchy
I''ve been stumbling on the tut at oriontransfer (http://wiki.oriontransfer.co.nz/main/show/SortableTree) I''ve got it working in a one dimensional list and I''ve got the drag and drop working on children, but as can''t get it to save the tree. Here''s my view: <h2>Menu Prototype 2</h2> <%= flash[:notice] %> <ul
2006 Feb 01
2
How do you display nested elements in their hierarchy?
Hello; I''d like some pointers on how to display nested items in their hierarchy. I''m developing a project that uses habtm (as opposed to "acts as tree"). I can interact with the elements using "parent", "child" etc. fine. I just can''t figure out how to make the elements *display* in their relationships. For example, if Ruby on Rails is
2006 Mar 25
2
acts_as_tree wierdness with children.count and children.size
i am making a category tree and i iterate over the category using my counter_cache however it would show a different number than what was actually being represetned in the tree. Here is an example cat.children = [cat2, cat3] puts cat.children.size 2 puts cat.children_count 2 cat4.parent_id = cat.id cat4.save puts cat.children.size
2006 Mar 22
10
Need for multiple acts_as_list
I have a model "Childmodel" that belongs_to two other models "Parent1" and "Parent2". "Parent1" "has_many :childmodels, :order => :positionp1" and "Parent2" "has_many :childmodels, :order => :positionp2". i.e. The child is independently positioned within each of its parents. This works fine and gets me the useful
2006 Jun 07
2
destroy on has_many relationships.
i need to delete a record from the database and delete all of it''s children as well. is there a method for this? right now, i am finding all the children with the parent_id and destroying them first and then destroying the parent. seems like there would be a better way to do this but i can''t seem to figure it out. thanks, josh -- Posted via http://www.ruby-forum.com/.
2006 Feb 02
3
acts_as_family_tree
For a project that I am working on I need to have a family tree. This means that instead of having one parent each item has at most two. As far as I know acts_as_tree only allows one parent_id. Any suggestions on how to make a "acts_as_family_tree" ? Thanks, Mark -- -------------------------------------------------------------------- I am Mark Daggett and I approve this message.
2007 Feb 14
3
eager loading parents and children (acts_as_tree)
I am struggling with how to do eager loading of an acts_as_tree model. If the model Stuff acts_as_tree I know I can do this to get children as well: Stuff.find(:all, :include => :children) But what if the model I am including is the one that acts_as_tree? For example, say Picture belongs_to Category. Category acts_as_tree and I want to get all pictures that are members of a category that
2008 May 27
2
HABTM using two columns
Hi all, I was wondering whether anyone could guide me to docu and code examples how to create and use a has_and_belongs_to_many relationship with a joining table where TWO columns are used to identify the relation to TWO alternative tables. Example: table 1: mothers [mother_id, name] table 2: fathers [father_id, name] table 3: children [child_id, name] joining table 4: children_parent
2006 Jan 12
4
How do you create a tree strucutre with ActiveRecord
I want to build an application that has the concept of administrative domains. What I mean by this is that administrators have access to different data, based on what domains they are a member of. The domain strucutre is hierarchical. Here is an example: - MLB - AL - East - Yankees - Red Sox ... + Central + West - NL + East + Central + West Now
2005 Jul 25
2
acts_as_tree and traversing parent/child relationships
I am working on an Rails application that uses a pretty complex category structure through out the site. I have defined a table to house all the info and a FK to reference parents within the table CREATE TABLE categories ( id int(11) NOT NULL auto_increment, name varchar(50) NOT NULL, parent_id int(11) default NULL, constraint fk_category_id foreign key (category_id) references
2007 Oct 22
1
self-referential habtm: why are my keys null?
I''m trying to set up a directional self-referential HABTM to represent an arbitrary semi-hierarchical structure; it works for any data prepopulated into the db, but when I try to create a new relationship, I just get NULLs in both key columns (or 0''s if I turn on the no-null constraint). Here are the migrations: class CreateNodes < ActiveRecord::Migration def self.up