# Associating a field with each page

**URL:** <https://www.ruby-forum.com/t/associating-a-field-with-each-page/109379>\
**Category:** Radiant CMS\
**Created:** [July 13, 2007, 9:48pm UTC](https://www.ruby-forum.com/t/associating-a-field-with-each-page/109379 "2007-07-13T21:48:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joe\_Lapp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9fc29f/32.png) [@Joe\_Lapp](https://www.ruby-forum.com/u/Joe_Lapp)\
**Post date:** [July 13, 2007, 9:48pm UTC](https://www.ruby-forum.com/t/associating-a-field-with-each-page/109379/1 "2007-07-13T21:48:41Z")

</div>

Hi everyone,

I’d like to create a set of pages having two fields per page: a body  
and an image URL. The layout will centrally control the positioning  
and formatting of the image across all pages, which is why I don’t  
want to embed the image separately in each page.

How do I do this? Do I manually create an “image” tab for each new  
page, and then have my layout retrieve the URL from this image tab?  
Adding the tab to the parent page doesn’t result in the children  
inheriting it.

Also, I assume that each tab correlates to a VARCHAR in the database.  
Is there a more efficient way to do this?

Thanks!  
~joe

P.S. I’m an experienced web/software developer, but new to both Ruby  
and Radiant.

---

<div class="post-metadata">

**Author:** ![Joe\_Lapp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9fc29f/32.png) [@Joe\_Lapp](https://www.ruby-forum.com/u/Joe_Lapp)\
**Post date:** [July 13, 2007, 10:22pm UTC](https://www.ruby-forum.com/t/associating-a-field-with-each-page/109379/2 "2007-07-13T22:22:45Z")

</div>

Il giorno 13/lug/07, alle ore 21:39, Joe Lapp ha scritto:

> Adding the tab to the parent page doesn’t result in the children  
> inheriting it.

I use DefaultPageParts extension:

[http://darcs.bigchieflabs.com/radiant/extensions/default\_page\_parts/](http://darcs.bigchieflabs.com/radiant/extensions/default_page_parts/)  
rdoc/

Let me know if it is what you need!

* * *

Andrea F.

removed\_email\_address@domain.invalid  
[http://bigchieflabs.com/blog/](http://bigchieflabs.com/blog/)  
[http://think.bigchief.it](http://think.bigchief.it)

---

<div class="post-metadata">

**Author:** ![Joe\_Lapp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9fc29f/32.png) [@Joe\_Lapp](https://www.ruby-forum.com/u/Joe_Lapp)\
**Post date:** [July 13, 2007, 10:43pm UTC](https://www.ruby-forum.com/t/associating-a-field-with-each-page/109379/3 "2007-07-13T22:43:48Z")

</div>

Joe Lapp wrote:

> Hi everyone,
> 
> I’d like to create a set of pages having two fields per page: a body  
> and an image URL. The layout will centrally control the positioning  
> and formatting of the image across all pages, which is why I don’t  
> want to embed the image separately in each page.
> 
> How do I do this? Do I manually create an “image” tab for each new  
> page, and then have my layout retrieve the URL from this image tab?

That is one way to do it.

> Adding the tab to the parent page doesn’t result in the children  
> inheriting it.

Make sure that you include inherit=“true” in the layout: \<r:content  
part=“image” inherit=“true” /\>  
This will force Radiant to look through parent pages until it finds a  
matching part with that name.

> Also, I assume that each tab correlates to a VARCHAR in the database.  
> Is there a more efficient way to do this?

Actually, it corresponds (roughly) to a record in a separate table in  
the database. There are more efficient ways, but they would involve  
writing an extension.

Andrea’s DefaultPageParts might help you with automatically creating the  
tabs.

Sean

---

<div class="post-metadata">

**Author:** ![Joe\_Lapp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9fc29f/32.png) [@Joe\_Lapp](https://www.ruby-forum.com/u/Joe_Lapp)\
**Post date:** [July 18, 2007, 3:34am UTC](https://www.ruby-forum.com/t/associating-a-field-with-each-page/109379/4 "2007-07-18T03:34:04Z")

</div>

Can anyone confirm for me the appropriate way to install an extension?

Do I just run rake from the extension’s directory? I can find web  
pages on creating extensions but not on installing them. (Maybe it’s  
obvious to people familiar with rails; I’m new to ruby/rails.)

If running rake is supposed to suffice, can anyone explain why it  
didn’t work for me? I now have the extension listed on my extensions  
page, but the DefaultPageParts page type doesn’t show for any page.  
See rake output below. Thanks!

~joe

---

<div class="post-metadata">

**Author:** ![Joe\_Lapp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9fc29f/32.png) [@Joe\_Lapp](https://www.ruby-forum.com/u/Joe_Lapp)\
**Post date:** [July 15, 2007, 6:25am UTC](https://www.ruby-forum.com/t/associating-a-field-with-each-page/109379/5 "2007-07-15T06:25:59Z")

</div>

Hi Andrea. Your extension looks perfect. I used darcs to pull it  
into the extensions directory. But heck if I know how to get the  
thing installed. An update on the admin page did nothing, and running  
rake from the default\_page\_parts directory resulted in this:

(in /var/www/ecotwined/vendor/extensions/default\_page\_parts)  
/usr/bin/ruby1.8 -Ilib:lib  
“/usr/lib/ruby/1.8/rake/rake\_test\_loader.rb”  
“test/functional/default\_page\_parts\_extension\_test.rb”  
Extensions cannot be used until Radiant migrations are up to date.  
Loaded suite /usr/lib/ruby/1.8/rake/rake\_test\_loader  
Started  
EF  
Finished in 0.006811 seconds.

1. Error:  
test\_initialization(DefaultPagePartsExtensionTest):  
NameError: uninitialized constant  
DefaultPagePartsExtensionTest::DefaultPagePartsExtension  
/var/lib/gems/1.8/gems/radiant-0.6.2/vendor/rails/activerecord/lib/…/…/activesupport/lib/active\_support/dependencies.rb:477:in  
`const_missing' ./test/functional/default_page_parts_extension_test.rb:11:in`test\_initialization’

2. Failure:  
test\_this\_extension(DefaultPagePartsExtensionTest)  
[./test/functional/default\_page\_parts\_extension\_test.rb:7]:  
Flunked.

2 tests, 1 assertions, 1 failures, 1 errors  
rake aborted!  
Command failed with status (1): [/usr/bin/ruby1.8 -Ilib:lib  
"/usr/lib/ruby/…]
