Adding my controller in an extension

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
Free Software Developers Meeting: http://www.fosdem.org

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

Sean

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

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 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)
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. [email protected] wrote:

steps involved in doing what I want? Is this correct:


Radiant mailing list
Post: [email protected]
Search: http://radiantcms.org/mailing-list/search/
Site: http://lists.radiantcms.org/mailman/listinfo/radiant


Web database: http://www.myowndb.com
Free Software Developers Meeting: http://www.fosdem.org

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

Quoting Raphael B. [email protected]:

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

On 4/6/07, Todd McGrath [email protected] 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
Free Software Developers Meeting: http://www.fosdem.org

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

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
Free Software Developers Meeting: http://www.fosdem.org