Using Rails methods in Radiant Plugins?

Last week I successfully deployed a website on Radiant. Yeah! This week
I’ve been struggling to extend the site with two different tools.

The first is a simple page protection system that forces some public
pages to require a password before their content is shown. Easy
enough… I think.

I kind of assumed I would be able to rely on some Rails helper methods
such as redirect_to(). Am I wrong, or am I just setting up my plugin

Here’s the basic outline of my plugin:

# /vendor/extensions/page_protect/page_protect_extension.rb

class PageProtectExtension < Radiant::Extension
  version "1.0"
  description "Adds PageProtect tags to force logins on specified pages"

  #define_routes do |map|

  def activate
    Page.send :include, PageProtect
# /vendor/extensions/page_protect/lib/page_protect.rb

module PageProtect
  include Radiant::Taggable

  def cache_page?

  tag 'pageprotect' do |tag|

  tag 'pageprotect:lockdown' do |tag|
    # use Rails redirect_to() to send user to the login screen
    redirect_to(:controller => "/login")

  tag 'pageprotect:loginform' do |tag|
    # output the HTML form stuff here


When I include the radius tag <r:pageprotect:lockdown /> in a page, I
see the following error:
“undefined method `redirect_to’ for #”

Any help is much appreciated!

On 3/22/07, David P. [email protected] wrote:


Hi David,

redirect_to is a method of ActionController::Base. In your code, you
include your tags and methods into the Page model, which doesn’t
inherit from ActionController. Hence the undefined error.

Try creating a helper method that redirects to the login page and call
that from your tag.

Good luck,

Sander de Goeij
[email protected]

Thanks for the suggestion. I’m still trying to chisel away at the three
years of OO-PHP burned into my brain.