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
incorrectly?
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|
#end
def activate
Page.send :include, PageProtect
end
end
# /vendor/extensions/page_protect/lib/page_protect.rb
module PageProtect
include Radiant::Taggable
def cache_page?
false
end
tag 'pageprotect' do |tag|
tag.expand
end
tag 'pageprotect:lockdown' do |tag|
# use Rails redirect_to() to send user to the login screen
redirect_to(:controller => "/login")
end
tag 'pageprotect:loginform' do |tag|
# output the HTML form stuff here
end
end
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!