# Adding my controller in an extension

**URL:** <https://www.ruby-forum.com/t/adding-my-controller-in-an-extension/90853>\
**Category:** Radiant CMS\
**Created:** [April 2, 2007, 12:54pm UTC](https://www.ruby-forum.com/t/adding-my-controller-in-an-extension/90853 "2007-04-02T12:54:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![raphael\_b](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7c8e57/32.png) [@raphael\_b](https://www.ruby-forum.com/u/raphael_b)\
**Post date:** [April 2, 2007, 12:54pm UTC](https://www.ruby-forum.com/t/adding-my-controller-in-an-extension/90853/1 "2007-04-02T12:54:56Z")

</div>

Hi,

I’m looking to add code to handle a form’s action. I wanted to add  
extension with a controller, but got stuck into problems. What are the  
steps involved in doing what I want? Is this correct:

- generate my extension
- edit the extension’s class (child of Radiant::Extension) to add a  
route to my controller. Question: is the controller visible or should  
I require a certain file, or alter the paths searched for requires?
- write my tests and controller code

Thanks in advance

Raph

–  
Web database: [http://www.myowndb.com](http://www.myowndb.com)  
Free Software Developers Meeting: [http://www.fosdem.org](http://www.fosdem.org)

---

<div class="post-metadata">

**Author:** ![raphael\_b](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7c8e57/32.png) [@raphael\_b](https://www.ruby-forum.com/u/raphael_b)\
**Post date:** [April 2, 2007, 5:02pm UTC](https://www.ruby-forum.com/t/adding-my-controller-in-an-extension/90853/2 "2007-04-02T17:02:44Z")

</div>

Sounds like you’re going down the right path. What problems were you  
running into?

Sean

---

<div class="post-metadata">

**Author:** ![raphael\_b](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7c8e57/32.png) [@raphael\_b](https://www.ruby-forum.com/u/raphael_b)\
**Post date:** [April 3, 2007, 9:51am UTC](https://www.ruby-forum.com/t/adding-my-controller-in-an-extension/90853/3 "2007-04-03T09:51:40Z")

</div>

I’m working on a simple mailer extension (I know the mailer extension,  
it doesn’t do whatn I need 😉

When working with the latest 0.6 gems, the controller is not found. I  
had to add this to simple\_mailer\_extension.rb:

require File.dirname( **FILE** ) + ‘/app/controllers/simple\_mailer’

but then I got

/usr/lib/ruby/gems/1.8/gems/radiant-0.6.0/vendor/rails/activesupport/lib/active\_support/dependencies.rb:266:in  
`load\_missing\_constant’: uninitialized constant ApplicationController  
(NameError)

I then went another way and checked out radiant from the svn  
repository. In the simple\_mailer\_extension.rb file, I add this:

define\_routes do |map|  
map.connect ‘/simple\_mailer/:action’, :controller =\>  
‘simple\_mailer’  
end

And I have a simple\_mailer controller:  
$ cat  
vendor/extensions/simple\_mailer/app/controllers/simple\_mailer\_controller.rb  
class SimpleMailerController \< ApplicationController  
def index  
end  
end

When I try to access [http://localhost:3000/simple\_mailer/index](http://localhost:3000/simple_mailer/index) I get  
an error. Here’s what I get in the log file:

Processing SiteController#show\_page (for 127.0.0.1 at 2007-04-03  
09:40:25) [GET]  
Parameters: {“action”=\>“show\_page”, “url”=\>[“simple\_mailer”,  
“index”], “controller”=\>“site”}

NameError (undefined local variable or method `behavior_id' for #<Page:0xb7642820>): .//vendor/rails/activerecord/lib/active_record/base.rb:1792:in `method\_missing’  
.//app/models/page.rb:62:in `behavior' /lib/advanced_delegation.rb:10:in `find\_by\_url’  
.//app/models/page.rb:72:in `find_by_url' .//app/controllers/site_controller.rb:29:in `find\_page’  
.//app/controllers/site\_controller.rb:34:in `show_uncached_page' .//app/controllers/site_controller.rb:22:in `show\_page’  
.//vendor/rails/actionpack/lib/action\_controller/base.rb:941:in  
`perform_action_without_filters' .//vendor/rails/actionpack/lib/action_controller/filters.rb:368:in `perform\_action\_without\_benchmark’  
.//vendor/rails/actionpack/lib/action\_controller/benchmarking.rb:69:in  
`perform_action_without_rescue' /usr/local/lib/site_ruby/1.8/benchmark.rb:300:in `measure’  
.//vendor/rails/actionpack/lib/action\_controller/benchmarking.rb:69:in  
`perform_action_without_rescue' .//vendor/rails/actionpack/lib/action_controller/rescue.rb:82:in `perform\_action’  
.//vendor/rails/actionpack/lib/action\_controller/base.rb:408:in  
`process_without_filters' .//vendor/rails/actionpack/lib/action_controller/filters.rb:377:in `process\_without\_session\_management\_support’  
.//vendor/rails/actionpack/lib/action\_controller/session\_management.rb:117:in  
`process' .//vendor/rails/railties/lib/dispatcher.rb:38:in `dispatch’  
.//vendor/rails/railties/lib/webrick\_server.rb:115:in  
`handle_dispatch' .//vendor/rails/railties/lib/webrick_server.rb:81:in `service’  
/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service' /usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run’  
/usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread' /usr/lib/ruby/1.8/webrick/server.rb:162:in `start\_thread’  
/usr/lib/ruby/1.8/webrick/server.rb:95:in `start' /usr/lib/ruby/1.8/webrick/server.rb:92:in `start’  
/usr/lib/ruby/1.8/webrick/server.rb:23:in `start' /usr/lib/ruby/1.8/webrick/server.rb:82:in `start’  
.//vendor/rails/railties/lib/webrick\_server.rb:67:in `dispatch' .//vendor/rails/railties/lib/commands/servers/webrick.rb:59 .//vendor/rails/activesupport/lib/active_support/dependencies.rb:147:in `require’  
.//vendor/rails/railties/lib/commands/server.rb:30  
./script/server:3

Rendering  
./script/…/config/…/vendor/rails/actionpack/lib/action\_controller/templates/rescues/layout.rhtml  
(500 Internal Error)

It seems the request is not routed correctly. I took a look at the  
ldap extension  
([http://dev.radiantcms.org/radiant/browser/branches/mental/extensions/ldap](http://dev.radiantcms.org/radiant/browser/branches/mental/extensions/ldap))  
but didn’t find any indication of what I’m doing wrong. I guess it  
could be a really simple thing I forgot to do…

Thanks in advance for your help

Raph

On 4/2/07, Sean C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > steps involved in doing what I want? Is this correct:
> 
> * * *
> 
> Radiant mailing list  
> Post: removed\_email\_address@domain.invalid  
> Search: [http://radiantcms.org/mailing-list/search/](http://radiantcms.org/mailing-list/search/)  
> Site: [http://lists.radiantcms.org/mailman/listinfo/radiant](http://lists.radiantcms.org/mailman/listinfo/radiant)

–  
Web database: [http://www.myowndb.com](http://www.myowndb.com)  
Free Software Developers Meeting: [http://www.fosdem.org](http://www.fosdem.org)

---

<div class="post-metadata">

**Author:** ![raphael\_b](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7c8e57/32.png) [@raphael\_b](https://www.ruby-forum.com/u/raphael_b)\
**Post date:** [April 3, 2007, 9:54pm UTC](https://www.ruby-forum.com/t/adding-my-controller-in-an-extension/90853/4 "2007-04-03T21:54:07Z")

</div>

On Apr 3, 2007, at 3:50 AM, Raphael B. wrote:

> (NameError)  
> This is a problem that continues to come up. In the latest extension  
> generator, as found in mental today, you will see that there is a  
> line at the top of the generated extension:

# Uncomment this if you reference any of your controllers in activate

# require\_dependency ‘application’

So, that could help.

> NameError (undefined local variable or method `behavior\_id’ for  
> #Page:0xb7642820):

Now this is interesting. You can see in migration 010 that  
behavior\_id’s should not be an aspect of Radiant in 0.6.0.

adam williams

---

<div class="post-metadata">

**Author:** ![raphael\_b](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7c8e57/32.png) [@raphael\_b](https://www.ruby-forum.com/u/raphael_b)\
**Post date:** [April 6, 2007, 6:59pm UTC](https://www.ruby-forum.com/t/adding-my-controller-in-an-extension/90853/5 "2007-04-06T18:59:05Z")

</div>

Quoting Raphael B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> When require the application dependency, the route is followed, but it  
> requires me to log into radiant. Can I also develop an extension that  
> is available without the need to log into radiant?

Hi,  
I found adding “no\_login\_required” to my controller helped-

class ExampleController \< ApplicationController

no\_login\_required

…

Todd

---

<div class="post-metadata">

**Author:** ![raphael\_b](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7c8e57/32.png) [@raphael\_b](https://www.ruby-forum.com/u/raphael_b)\
**Post date:** [April 9, 2007, 5:29pm UTC](https://www.ruby-forum.com/t/adding-my-controller-in-an-extension/90853/6 "2007-04-09T17:29:07Z")

</div>

On 4/6/07, Todd McGrath [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> no\_login\_required

That’s working!

thanks Todd!

Raph

PS: Did I miss a documentation resource where this is indicated?

–  
Web database: [http://www.myowndb.com](http://www.myowndb.com)  
Free Software Developers Meeting: [http://www.fosdem.org](http://www.fosdem.org)

---

<div class="post-metadata">

**Author:** ![raphael\_b](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7c8e57/32.png) [@raphael\_b](https://www.ruby-forum.com/u/raphael_b)\
**Post date:** [April 6, 2007, 6:41pm UTC](https://www.ruby-forum.com/t/adding-my-controller-in-an-extension/90853/7 "2007-04-06T18:41:38Z")

</div>

> # require\_dependency ‘application’
> 
> So, that could help.

It helps indeed, but I didn’t have this comment in the generated  
extension. This is with the 0.6rc2 and the svn checkout I did some  
days ago:

$ ./script/generate extension test  
…  
$ cat vendor/extensions/test/test\_extension.rb  
class TestExtension \< Radiant::Extension  
version “1.0”  
description “Describe your extension here”  
url “[Fastest Web Hosting Services | Buy High Quality Hosting](http://yourwebsite.com/test)”

# define\_routes do |map|

# map.connect ‘admin/test/:action’, :controller =\> ‘admin/test’

# end

def activate  
# admin.tabs.add “Test”, “/admin/test”, :after =\> “Layouts”,  
:visibility =\> [:all]  
end

def deactivate  
# admin.tabs.remove “Test”  
end

end

When require the application dependency, the route is followed, but it  
requires me to log into radiant. Can I also develop an extension that  
is available without the need to log into radiant? I simply want to  
add a controller that doesn’t need an admin part. What if eg I want to  
let people leave their email to I can contact them later on? I though  
I’d do that with a controller to which the form is submitted, but then  
this controller has to be available without logging into radiant. Or  
shold I go in the direction of a plugin/engine?

Thanks for your help

Raph

–  
Web database: [http://www.myowndb.com](http://www.myowndb.com)  
Free Software Developers Meeting: [http://www.fosdem.org](http://www.fosdem.org)
