Forum: Ruby on Rails Calling RESTful 'scoped' INDEX when params[] is no

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
36f02ca8773a0bdc3f2d90a932c1b8b3?d=identicon&s=25 (Guest)
on 2007-06-19 13:50
(Received via mailing list)
I have a VERY hierchical database and am using a RESTful
approach.  Normally, when users' enter the system they'll cascade
level to level in the database and thus the hierchical information
such as child.parent.grandchild_id are always available to the
However, when I attempt to directly call a middle level table.index I
obviously fail, because the parent_id is not available to pass to the
RESTful route.
I'd like to have a 'safety mechanism' built into my code that handles
this by simple displaying all records irrespective of
    Here is an example of my before_filter event and the way I use it
to call my index:

def find_parent
@find_parent || @project = Project.find(params[:project_id])

Here is a typical table.index action:

def index
  @portals = @project.portals.find :all

Would it be possible to make the INDEX code something like this;

def index
if @project.nil?
  @portals = Portal.find :all
  @portals = @project.portals.find :all,

    Fundumentally, what 'blows my mind' is that the 'find_parent'
'before_filter' event ALWAYS has to fire and if no parent exists, I
can't see how to return a '...@project.nil' or whatever is needed to
the if, else routine (above)?

Thank you,
This topic is locked and can not be replied to.