# Problem getting radiant-mental with custom extension working

**URL:** <https://www.ruby-forum.com/t/problem-getting-radiant-mental-with-custom-extension-working/84548>\
**Category:** Radiant CMS\
**Created:** [February 5, 2007, 10:31pm UTC](https://www.ruby-forum.com/t/problem-getting-radiant-mental-with-custom-extension-working/84548 "2007-02-05T22:31:20Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsmorris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@jsmorris](https://www.ruby-forum.com/u/jsmorris)\
**Post date:** [February 5, 2007, 10:31pm UTC](https://www.ruby-forum.com/t/problem-getting-radiant-mental-with-custom-extension-working/84548/1 "2007-02-05T22:31:20Z")

</div>

I moved my bits from my dev box; mac os x 10.4.9, ruby 1.8.5,  
radiant(mental branch) r303 running on mongrel to my host  
railsplayground.

On railsplayground, the server is running fcgi, but radiant is up and  
working. It is serving my pages just fine. However, my trouble  
starts with my custom extension that I wrote. Again, it works  
perfectly fine on my dev box, but on the hosting site it throws this  
error when I try to access it from the admin portion of radiant:

Processing ApplicationController#index (for 70.190.32.209 at  
2007-02-05 15:00:20) [GET]  
Session ID: 19c91a04a06891d8c0f825b6663d062f  
Parameters: {“action”=\>“index”, “controller”=\>“admin/lectures”}

NameError (uninitialized constant Admin::LecturesController):  
/vendor/rails/activerecord/lib/…/…/activesupport/lib/active\_support/dependencies.rb:267:in  
`load_missing_constant' /vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:453:in`const\_missing’  
/vendor/rails/activerecord/lib/…/…/activesupport/lib/active\_support/inflector.rb:251:in  
`constantize' /vendor/rails/activerecord/lib/../../activesupport/lib/active_support/core_ext/string/inflections.rb:148:in`constantize’  
/vendor/rails/actionpack/lib/action\_controller/routing.rb:1258:in  
`recognize' /vendor/rails/railties/lib/dispatcher.rb:40:in`dispatch’  
/vendor/rails/railties/lib/fcgi\_handler.rb:168:in `process_request' /vendor/rails/railties/lib/fcgi_handler.rb:143:in`process\_each\_request!’  
/vendor/rails/railties/lib/fcgi\_handler.rb:109:in  
`with_signal_handler' /vendor/rails/railties/lib/fcgi_handler.rb:142:in`process\_each\_request!’  
/usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:612:in  
`each_cgi' /usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:609:in`each’  
/usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:609:in  
`each_cgi' /vendor/rails/railties/lib/fcgi_handler.rb:141:in`process\_each\_request!’  
/vendor/rails/railties/lib/fcgi\_handler.rb:55:in `process!' /vendor/rails/railties/lib/fcgi_handler.rb:25:in`process!’  
dispatch.fcgi:24

My extension configuration is

define\_routes do |map|  
map.connect ‘admin/education/:action’, :controller =\>  
‘admin/lectures’  
end

def activate  
admin.tabs.add “Education”, “/admin/education”, :after =\>  
“Layouts”, :visibility =\> [:all]  
Page.send :include, LecturesTag  
NoCachePage  
end

The funny thing is that on the first request (after the fcgi process  
is restarted) works, but the second request gets this error.

I have double-checked all configuration issues with railsplayground  
and verified that it works locally on my dev machine. Anyone have any  
hints as to what is going on?

I have even compared file by file between local and hosted and nothing  
is different except the difference needed by fcgi on railsplayground.

Any help would be appreciated.

Jason

---

<div class="post-metadata">

**Author:** ![jsmorris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@jsmorris](https://www.ruby-forum.com/u/jsmorris)\
**Post date:** [February 5, 2007, 10:39pm UTC](https://www.ruby-forum.com/t/problem-getting-radiant-mental-with-custom-extension-working/84548/2 "2007-02-05T22:39:22Z")

</div>

I suspect the difference is between development mode and production  
mode.  
However, I would double-check that your controller looks like so:

class Admin::LecturesController \< ApplicationController

# your actions…

end

Generally, in my extensions, I stay away from namespacing my controllers  
and  
get away with it by prefixing the route with /admin. It makes things a  
little easier.

Sean

---

<div class="post-metadata">

**Author:** ![jsmorris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@jsmorris](https://www.ruby-forum.com/u/jsmorris)\
**Post date:** [February 5, 2007, 11:43pm UTC](https://www.ruby-forum.com/t/problem-getting-radiant-mental-with-custom-extension-working/84548/3 "2007-02-05T23:43:32Z")

</div>

Thanks for the help…at least now I have some thing to try.

Since you suggested two things to try, I tried all combinations and  
here are my results

Scenario 1: original route (no leading slashes) / namespace on  
controller

define\_routes do |map|  
map.connect ‘admin/education/:action’, :controller =\> ‘admin/lectures’  
end

class Admin::LecturesController \< ApplicationController

dev: broke…couldn’t find controller  
prod: found controller, but couldn’t find the views

Scenario 2: original route (no leading slashes) / no namespace on  
controller (original configuration)

define\_routes do |map|  
map.connect ‘admin/education/:action’, :controller =\> ‘admin/lectures’  
end

class LecturesController \< ApplicationController

dev: works correctly  
prod: cannot found controller

Scenario 3: modified route (leading slashes) / no namespace on  
controller

define\_routes do |map|  
map.connect ‘/admin/education/:action’, :controller =\>  
‘/admin/lectures’  
end

class LecturesController \< ApplicationController

dev: works correctly  
prod: cannot found controller

Scenario 4: modified route (leading slashes) / namespace on controller

define\_routes do |map|  
map.connect ‘/admin/education/:action’, :controller =\>  
‘/admin/lectures’  
end

class LecturesController \< ApplicationController

dev: broke, cannot find controller  
prod: cannot find views

So, it looks like I need to add the Admin:: to my controller in my  
extension for production only. But, still not functional until I  
copied my views from the extension directory to the main app  
directory.

This is a complete hack, but it works as far as I can see…now is  
there an explanation as to why this is happening?

---

<div class="post-metadata">

**Author:** ![jsmorris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@jsmorris](https://www.ruby-forum.com/u/jsmorris)\
**Post date:** [February 6, 2007, 5:27am UTC](https://www.ruby-forum.com/t/problem-getting-radiant-mental-with-custom-extension-working/84548/4 "2007-02-06T05:27:05Z")

</div>

I too am having issues like this.

I solve them temporarily with explicit “load” calls in various places

i.e. at the end of page.rb in core I added  
load  
“#{RADIANT\_ROOT}/vendor/extensions/page\_attributes/app/models/page.rb”

My hope is that I’ll be able to complete my extension with a bunch of  
these hacks, and then go back and figure out a way to make it work  
properly. I have a feeling the way that Radiant currently loads up all  
extension code is insufficient, but until I have a completed working  
extension I can’t completely narrow the blame. I suspect there are  
changes that should be made in Radiant Core code, but I can’t  
rationalize them until I have an extension that demonstrates the need.

Also, I noticed sometimes routes.rb gets loaded befor routes defined in  
my extension. Which leads to all URLs generated resolving to  
site\_controller.

(due to : site.connect ‘\*url’, :action =\> ‘show\_page’ )

So I actually added a line just before the site controller stuff so that  
I would have a generic route for everything:  
map.connect ‘admin/extensions/:controller/:action’

---

<div class="post-metadata">

**Author:** ![jsmorris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@jsmorris](https://www.ruby-forum.com/u/jsmorris)\
**Post date:** [February 6, 2007, 5:54am UTC](https://www.ruby-forum.com/t/problem-getting-radiant-mental-with-custom-extension-working/84548/5 "2007-02-06T05:54:56Z")

</div>

> So, it looks like I need to add the Admin:: to my controller in my  
> extension for production only. But, still not functional until I  
> copied my views from the extension directory to the main app  
> directory.
> 
> This is a complete hack, but it works as far as I can see…now is  
> there an explanation as to why this is happening?

Can’t tell you what you’ve done wrong, as I can’t reproduce it. Look at:

[http://soxbox.no-ip.org/test/test\_extension.tar.gz](http://soxbox.no-ip.org/test/test_extension.tar.gz)

If you can’t see what you’ve done wrong, create the smallest possible  
extension that you can to demonstrate your problem and file a ticket (at  
[http://dev.radiantcms.org/](http://dev.radiantcms.org/) - you’ll need to register).

Dan.

---

<div class="post-metadata">

**Author:** ![jsmorris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@jsmorris](https://www.ruby-forum.com/u/jsmorris)\
**Post date:** [February 6, 2007, 6:14am UTC](https://www.ruby-forum.com/t/problem-getting-radiant-mental-with-custom-extension-working/84548/6 "2007-02-06T06:14:57Z")

</div>

I will keep trying things to keep narrowing it down. At this point, I  
cannot determine if it is my code in the extension, radiant, or my  
hosting provider.

I will report back as soon as I know something.

---

<div class="post-metadata">

**Author:** ![jsmorris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@jsmorris](https://www.ruby-forum.com/u/jsmorris)\
**Post date:** [February 6, 2007, 7:34am UTC](https://www.ruby-forum.com/t/problem-getting-radiant-mental-with-custom-extension-working/84548/7 "2007-02-06T07:34:02Z")

</div>

I took your example and integrated it with my site and it appears to  
work. Granted your index view is not as complicated as mine, but I  
think I noticed a difference between this test extension and my  
extension.

The test extension, has a structure of

app/controllers/admin/name\_controller.rb  
app/views/admin/name/index.rhtml

but in my extension, I don’t have the intermediary admin folder, so I  
think that is why it cannot find the views/controllers.

That is only difference I can see. I loaded this extension in both my  
local dev environment and my production site and it works.

Next, I want to edit my extension with what I learned to see if I can  
remove the hack I put in.

Thanks for you help.

Jason

---

<div class="post-metadata">

**Author:** ![jsmorris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@jsmorris](https://www.ruby-forum.com/u/jsmorris)\
**Post date:** [February 6, 2007, 2:41pm UTC](https://www.ruby-forum.com/t/problem-getting-radiant-mental-with-custom-extension-working/84548/8 "2007-02-06T14:41:20Z")

</div>

Jacob,

That sounds completely unnatural. As DHH has said (paraphrasing) “doing  
it  
the wrong way should hurt”. I haven’t had any problems with the way  
Radiant  
loads extensions – routes and classes load in the right order. It seems  
as  
if what you want is to mix a module into Page, rather than redefining  
the  
class. I’ll be on IRC today if you would like assistance.

Sean

---

<div class="post-metadata">

**Author:** ![jsmorris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@jsmorris](https://www.ruby-forum.com/u/jsmorris)\
**Post date:** [February 6, 2007, 6:10pm UTC](https://www.ruby-forum.com/t/problem-getting-radiant-mental-with-custom-extension-working/84548/9 "2007-02-06T18:10:27Z")

</div>

> loads extensions – routes and classes load in the right order. It seems  
> as  
> if what you want is to mix a module into Page, rather than redefining  
> the  
> class. I’ll be on IRC today if you would like assistance.
> 
> Sean

Thanks for the offer Sean, what about this weekend?

It looks like I will take the approach discussed above of submitting  
some “example” extensions that demonstrate my problems.

Sean, your idea to mix in a module work for adding methods to page, but  
breaks for things like has\_many and belongs\_to …

---

<div class="post-metadata">

**Author:** ![jsmorris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@jsmorris](https://www.ruby-forum.com/u/jsmorris)\
**Post date:** [February 6, 2007, 6:15pm UTC](https://www.ruby-forum.com/t/problem-getting-radiant-mental-with-custom-extension-working/84548/10 "2007-02-06T18:15:46Z")

</div>

Jacob,

Regarding has\_many and belongs\_to, etc – that is, class methods – you  
can  
use the singleton class in your `activate` method,

class \<\< Page  
has\_many :widgets  
end

-or- in the `included` method of your module do a class\_eval,

def included(base)  
base.class\_eval do  
has\_many :widgets  
end  
end

You could also use `send` to invoke the has\_many method. In other  
words,  
TIMTOWTDI.

Sean

---

<div class="post-metadata">

**Author:** ![jsmorris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@jsmorris](https://www.ruby-forum.com/u/jsmorris)\
**Post date:** [February 18, 2007, 11:42pm UTC](https://www.ruby-forum.com/t/problem-getting-radiant-mental-with-custom-extension-working/84548/11 "2007-02-18T23:42:04Z")

</div>

Sean C. wrote:

> class \<\< Page  
> has\_many :widgets  
> end
> 
> -or- in the `included` method of your module do a class\_eval,
> 
> def included(base)  
> base.class\_eval do  
> has\_many :widgets  
> end  
> end
> 
> You could also use `send` to invoke the has\_many method. In other

The first 2 methods don’t work at all.

I get  
undefined local variable or method `inherit\_from\_page’ for  
#Page:0x23a7f34

Using the first 2 techniques, where I’m adding a:  
belongs\_to :inherit\_from\_page, :class\_name =\> ‘Page’, :foreign\_key  
=\> ‘inherit\_from\_page\_id’

Using the third technique (explicit send calls) It actually “works” for  
the first page load, and then fails on subsequent loads.

What I think is really messing things up is rails trying to  
automatically load things. I have rails in dev mode, and it reloads  
changes to certain files, and not to other files. I havn’t been able to  
figure it out, but my suspicions is that the way files are loaded at  
startup is different from the way they are automatically reloaded.

I’ve been trying to look through the source attempting to figure out  
exactly how extensions are loaded. If someone familliar with the subject  
would hop on [irc.freenode.net](http://irc.freenode.net) and talk to igotimac about it… I would  
greatly appreciate any help.

thanks,  
Jacob

---

<div class="post-metadata">

**Author:** ![jsmorris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6f9a4e/32.png) [@jsmorris](https://www.ruby-forum.com/u/jsmorris)\
**Post date:** [February 19, 2007, 12:22am UTC](https://www.ruby-forum.com/t/problem-getting-radiant-mental-with-custom-extension-working/84548/12 "2007-02-19T00:22:57Z")

</div>

It’s always the simplest solution isn’t it…

I needed to do:

def self.included(base)

Instead of

def included(base)
