KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jun-17 12:03 UTC
Calling RESTful ''scoped'' INDEX when params[:parent.id] is not present?
Jordon,
I have a VERY hierchical database and am using a RESTful
approach. Normally, when users'' enter the system they''ll
cascade from
level to level in the database and thus the hierchical information
such as child.parent.grandchild_id are always available to the RESTful
routes.
However, when I attempt to simply 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, and provide the pieces that describe the problem.
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])
end
Here is a typical table.index action:
def index
@portal_pages = Paginator.new self, @project.portals.count, 3,
params[:page]
@portals = @project.portals.find :all,
:order => ''description'',
:limit => @portal_pages.items_per_page,
:offset => @portal_pages.current.offset
respond_to do |format|
format.html # index.rhtml
format.xml { render :xml => @portals.to_xml }
end
end
Would it be reasonable to make the INDEX code something like this;
def index
if @project.nil?
@portal_pages = Paginator.new self, Portal.count, 3, params[:page]
@portals = Portal.find :all,
:order => ''description'',
:limit => @portal_pages.items_per_page,
:offset => @portal_pages.current.offset
else
@portal_pages = Paginator.new self, @project.portals.count, 3,
params[:page]
@portals = @project.portals.find :all,
:order => ''description'',
:limit => @portal_pages.items_per_page,
:offset => @portal_pages.current.offset
end
respond_to do |format|
format.html # index.rhtml
format.xml { render :xml => @portals.to_xml }
end
end
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 feed
the if, else routine (above)?
Thank you,
Kathy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jun-19 11:48 UTC
Calling RESTful ''scoped'' INDEX when params[:parent.id] is not present?
I have a VERY hierchical database and am using a RESTful
approach. Normally, when users'' enter the system they''ll
cascade
from
level to level in the database and thus the hierchical information
such as child.parent.grandchild_id are always available to the
RESTful
routes.
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 parent.id.
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])
end
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
else
@portals = @project.portals.find :all,
end
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
feed
the if, else routine (above)?
Thank you,
Kathy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---