# Extending admin\_ui?

**URL:** <https://www.ruby-forum.com/t/extending-admin-ui/105192>\
**Category:** Radiant CMS\
**Created:** [May 27, 2007, 12:17am UTC](https://www.ruby-forum.com/t/extending-admin-ui/105192 "2007-05-27T00:17:14Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sbusso](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cc9497/32.png) [@sbusso](https://www.ruby-forum.com/u/sbusso)\
**Post date:** [May 27, 2007, 12:17am UTC](https://www.ruby-forum.com/t/extending-admin-ui/105192/1 "2007-05-27T00:17:14Z")

</div>

Hi everybody

I need your help.

I would like to know if it’s possile to extend the class AdminUI in  
module Radiant. I try to do it by creating a folder Radiant in the lib  
folder of my extension, and then create a module Radiant within a class  
AdminUI. In this class I modify the Tab class.

When I do that, my class is not loaded when server start.

Then, is it possible to extend the class AdminUi like this ?

Thanks for helping me.

–  
Stephane

---

<div class="post-metadata">

**Author:** ![sbusso](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cc9497/32.png) [@sbusso](https://www.ruby-forum.com/u/sbusso)\
**Post date:** [May 27, 2007, 4:18am UTC](https://www.ruby-forum.com/t/extending-admin-ui/105192/2 "2007-05-27T04:18:15Z")

</div>

On May 26, 2007, at 6:17 PM, Stephane B. wrote:

> I would like to know if it’s possile to extend the class AdminUI in  
> module Radiant. I try to do it by creating a folder Radiant in the lib  
> folder of my extension, and then create a module Radiant within a  
> class  
> AdminUI. In this class I modify the Tab class.
> 
> When I do that, my class is not loaded when server start.
> 
> Then, is it possible to extend the class AdminUi like this ?

Stephane, what is the goal of your efforts?

```
adam
```

---

<div class="post-metadata">

**Author:** ![sbusso](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cc9497/32.png) [@sbusso](https://www.ruby-forum.com/u/sbusso)\
**Post date:** [May 27, 2007, 11:14am UTC](https://www.ruby-forum.com/t/extending-admin-ui/105192/3 "2007-05-27T11:14:30Z")

</div>

Adam W. wrote:

> On May 26, 2007, at 6:17 PM, Stephane B. wrote:
> 
> > I would like to know if it’s possile to extend the class AdminUI in  
> > module Radiant. I try to do it by creating a folder Radiant in the lib  
> > folder of my extension, and then create a module Radiant within a  
> > class  
> > AdminUI. In this class I modify the Tab class.
> > 
> > When I do that, my class is not loaded when server start.
> > 
> > Then, is it possible to extend the class AdminUi like this ?
> 
> Stephane, what is the goal of your efforts?
> 
> ```
> adam
> 
> ```

I would like to create a second level of navigation when needed, then  
create a ‘sub tab’ system by simply extending current Tab with a TabSet  
accessor.  
need to

- add an accessor
- a method
- modify initialize

Stephane

---

<div class="post-metadata">

**Author:** ![sbusso](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cc9497/32.png) [@sbusso](https://www.ruby-forum.com/u/sbusso)\
**Post date:** [May 27, 2007, 11:21am UTC](https://www.ruby-forum.com/t/extending-admin-ui/105192/4 "2007-05-27T11:21:21Z")

</div>

> I would like to create a second level of navigation when needed, then  
> create a ‘sub tab’ system by simply extending current Tab with a TabSet  
> accessor.  
> need to
> 
> - add an accessor
> - a method
> - modify initialize

I did it already by patching the code but I would like to do it in an  
exension.

---

<div class="post-metadata">

**Author:** ![sbusso](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cc9497/32.png) [@sbusso](https://www.ruby-forum.com/u/sbusso)\
**Post date:** [May 27, 2007, 5:55pm UTC](https://www.ruby-forum.com/t/extending-admin-ui/105192/5 "2007-05-27T17:55:31Z")

</div>

It is a pretty standard Ruby practice to re-open the class, but  
sometimes I find this doesn’t work as expected. Instead, you can try  
doing a class\_eval or module\_eval on the intended class, which will  
make sure it’s auto-loaded before you try to override or extend it.  
Example:

Radiant::AdminUI::Tab.class\_eval {

# your code here

}

Cheers,

Sean

---

<div class="post-metadata">

**Author:** ![sbusso](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cc9497/32.png) [@sbusso](https://www.ruby-forum.com/u/sbusso)\
**Post date:** [May 27, 2007, 11:48pm UTC](https://www.ruby-forum.com/t/extending-admin-ui/105192/6 "2007-05-27T23:48:59Z")

</div>

Sean C. wrote:

> It is a pretty standard Ruby practice to re-open the class, but  
> sometimes I find this doesn’t work as expected. Instead, you can try  
> doing a class\_eval or module\_eval on the intended class, which will  
> make sure it’s auto-loaded before you try to override or extend it.  
> Example:
> 
> Radiant::AdminUI::Tab.class\_eval {
> 
> # your code here
> 
> }
> 
> Cheers,
> 
> Sean

Thanks for your help. Finally I put my extended code in the definition  
of the extension. It looks to work fine… but not really clean. It  
seems that only my folder lib/radiant can’t be loaded :(, is there any  
way to force to load this folder ?

I saw when creating a new class, it will load it only if I call an  
instance of it; only at this stage radiant/rails will look in the lib  
folder. Then in the case of Radiant::AdminUI I guess it will not look in  
lib as the class already exist.

Is it a matter of Radiant extension mechanism ?

I will try to improve my code and all suggestions are welcome 🙂

---

<div class="post-metadata">

**Author:** ![sbusso](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cc9497/32.png) [@sbusso](https://www.ruby-forum.com/u/sbusso)\
**Post date:** [May 28, 2007, 10:34pm UTC](https://www.ruby-forum.com/t/extending-admin-ui/105192/7 "2007-05-28T22:34:45Z")

</div>

Adam W. wrote:

> On May 27, 2007, at 5:48 PM, Stephane B. wrote:
> 
> > Is it a matter of Radiant extension mechanism ?

> If you do not care for the solution you have in place, you could  
> place your code in a file like /lib/radiant/admin\_ui\_ext.rb,  
> then in your extension loader, ‘require “radiant/admin\_ui\_ext”’. Now  
> the ugly is in the fact that you have a file named slightly  
> differently than the class it contains, and reloading will not work,  
> as far as I understand dependencies.rb (a Rails thing).
> 
> So, I guess you may have to leave it the way it is.
> 
> adam williams

I tried to do like this and I got “already initialized constant” error  
message. But mechanism is now clear for me. thanks for the help 🙂

---

<div class="post-metadata">

**Author:** ![sbusso](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cc9497/32.png) [@sbusso](https://www.ruby-forum.com/u/sbusso)\
**Post date:** [May 28, 2007, 1:31pm UTC](https://www.ruby-forum.com/t/extending-admin-ui/105192/8 "2007-05-28T13:31:08Z")

</div>

On May 27, 2007, at 5:48 PM, Stephane B. wrote:

> Is it a matter of Radiant extension mechanism ?

As you suspect, Radiant::AdminUI is discovered before your extension  
is loaded. Your file will not be discovered; the dependencies  
mechanism which provides for the discovery of missing constants will  
not be triggered - Radiant::AdminUI is not missing, though if it  
were, it would find it in your /lib.

If you do not care for the solution you have in place, you could  
place your code in a file like /lib/radiant/admin\_ui\_ext.rb,  
then in your extension loader, ‘require “radiant/admin\_ui\_ext”’. Now  
the ugly is in the fact that you have a file named slightly  
differently than the class it contains, and reloading will not work,  
as far as I understand dependencies.rb (a Rails thing).

So, I guess you may have to leave it the way it is.

adam williams
