Problem with virtual page(s) and find_by_url

I have the following setup:

Home Page
|
– People (PeoplePage)
|
– Person (PersonPage)
|
– Bio (BioPage)
– Contact (ContactInfoPage)

I made an extension with some Page Types (in parentheses) wich are used
to
display the list of people in the company and the data about a
particular
person, respectively (the latter being a virtual page).

Since a person object carries plenty of data I need to split the data
into
several pages, like:

/people/18 # 18 is an ID of a existing object
(Person)
/people/18/bio
/people/18/contact

It seems I have a problem with find_by_url in PersonPage:

def virtual?
true
end

def find_by_url(url, live = true, clean = true)
url = clean_url(url) if clean
if url =~ %r{#{parent.url}/\d+/bio/?$}
children.find_by_class_name ‘BioPage’
else
super
end
end

This looks fine to my untrained eye, but:

$ script/console
Loading development environment.

p = Page.find_by_url(’/people/18/bio/’)
=> #<FileNotFoundPage:0xb709db54 @attributes={“virtual”=>“1”,
“class_name”=>“FileNotFoundPage”, “slug”=>“file-not-found”,
“updated_at”=>“2008-01-24 00:47:14”, “title”=>“File Not Found”,
“created_by”=>“1”, “breadcrumb”=>“File Not Found”, “lock_version”=>“2”,
“updated_by”=>“1”, “id”=>“3”, “published_at”=>“2008-01-20 23:51:27”,
“status_id”=>“100”, “layout_id”=>nil, “parent_id”=>“2”,
“created_at”=>“2008-01-20 22:51:27”}>

Then, this works in the same console:

p = Page.find_by_url(’/people/18/’)
p.children.find_by_class_name ‘BioPage’

Regexp looks fine too, as far as I can tell. I know this is a cockpit
problem, but I need someone to point a finger at it, since I must be
(code)
blind or something. BioPage is declared virtual, too (if it matters).
Can
anyone suggest what could be wrong?

It seems it might be appropriate for your PersonPage to be virtual and
the PeoplePage to override find_by_url as well.

Sean

On Jan 29, 2008 9:42 PM, Sean C. [email protected] wrote:

It seems it might be appropriate for your PersonPage to be virtual and
the PeoplePage to override find_by_url as well.

Hi Sean,

Thanks for the reply. Both of the PersonPage and the BioPage are
virtual,
and in PeoplePage I have:

def find_by_url(url, live = true, clean = false)
url = clean_url(url) if clean
if url =~ %r{#{self.url}/?\d+/?$}
children.find_by_class_name ‘PersonPage’
else
super
end
end

def child_url(child)
clean_url “#{url}/#{child.id}”
end

I can get the pages by Page.find_by_url for the

/people/
/people/18

but it doesn’t work for

/people/18/bio

Its a wildest guess, but does it have anything to do with the fact that
I’m
redefining find_by_url in a virtual page (per se)? I’d say no, but just
to
be on the safe side…

nn wrote:

I made an extension with some Page Types (in parentheses) wich are used to
display the list of people in the company and the data about a particular
person, respectively (the latter being a virtual page).

Since a person object carries plenty of data I need to split the data into
several pages, like:

/people/18 # 18 is an ID of a existing object
(Person)
def find_by_url(url, live = true, clean = true)
$ script/console
“created_at”=>“2008-01-20 22:51:27”}>

Then, this works in the same console:

p = Page.find_by_url(’/people/18/’)
p.children.find_by_class_name ‘BioPage’

Regexp looks fine too, as far as I can tell. I know this is a cockpit
problem, but I need someone to point a finger at it, since I must be
(code)
blind or something. BioPage is declared virtual, too (if it matters). Can
anyone suggest what could be wrong?

In this find_by_url method, you return the PersonPage if the URL is
/people/18, but you don’t call its find_by_url if the URL is
/people/18/bio. Remove the $ from the regexp and then instead of
returning children.find_by_class_name(‘PersonPage’), return
children.find_by_class_name(‘PersonPage’).find_by_url(url, live,
clean). Then in your PersonPage, have several tests – one that matches
for itself (use the one below and substitute parent.url for self.url),
and then any special cases (/bio, /contact, etc) that return the
appropriate sub-page, then super.

If this is unclear, write me back and I’ll give more detail.

Sean

On Jan 29, 2008 10:26 PM, Sean C. [email protected] wrote:

If this is unclear, write me back and I’ll give more detail.
OK - got it. Thanks Sean.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs