# Using Rails methods in Radiant Plugins?

**URL:** <https://www.ruby-forum.com/t/using-rails-methods-in-radiant-plugins/89774>\
**Category:** Radiant CMS\
**Created:** [March 22, 2007, 5:55pm UTC](https://www.ruby-forum.com/t/using-rails-methods-in-radiant-plugins/89774 "2007-03-22T17:55:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dpitman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dpitman](https://www.ruby-forum.com/u/dpitman)\
**Post date:** [March 22, 2007, 5:55pm UTC](https://www.ruby-forum.com/t/using-rails-methods-in-radiant-plugins/89774/1 "2007-03-22T17:55:52Z")

</div>

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:

```auto
# /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
```

```auto
# /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!

---

<div class="post-metadata">

**Author:** ![dpitman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dpitman](https://www.ruby-forum.com/u/dpitman)\
**Post date:** [March 22, 2007, 8:33pm UTC](https://www.ruby-forum.com/t/using-rails-methods-in-radiant-plugins/89774/2 "2007-03-22T20:33:17Z")

</div>

On 3/22/07, David P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> end  
> end  
> [/code]

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  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![dpitman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dpitman](https://www.ruby-forum.com/u/dpitman)\
**Post date:** [March 23, 2007, 3:34pm UTC](https://www.ruby-forum.com/t/using-rails-methods-in-radiant-plugins/89774/3 "2007-03-23T15:34:32Z")

</div>

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