# Using Devise as an authentication solution for end users with Radiant - updated

**URL:** <https://www.ruby-forum.com/t/using-devise-as-an-authentication-solution-for-end-users-with-radiant-updated/198065>\
**Category:** Radiant CMS\
**Created:** [October 25, 2010, 9:38pm UTC](https://www.ruby-forum.com/t/using-devise-as-an-authentication-solution-for-end-users-with-radiant-updated/198065 "2010-10-25T21:38:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [October 25, 2010, 9:38pm UTC](https://www.ruby-forum.com/t/using-devise-as-an-authentication-solution-for-end-users-with-radiant-updated/198065/1 "2010-10-25T21:38:32Z")

</div>

(This is an updated version of a previous post. Update to point #3.  
Point #8 has been removed. I’ll be adding a Wiki article on this as  
well.)

All,

I’ve spent some time getting Devise working as an authentication system  
for my end users, and thought I would share how I got it to work.

1. Because Radiant already has a User model, you have to set up Devise  
to use a different model for authentication. So, you should choose a  
model name, and use that when you install Devise per the directions.  
For the purposes of the rest of this explanation, let’s assume that the  
model name is CustomUser.

2. Do all of your setup for Devise for CustomUser, including setting up  
the “devise\_for” route (devise\_for :custom\_user, etc.). I set up my  
Devise route in my custom extension’s routes.rb file.

3. To protect all of the end-user content, you need to call the Devise  
authenticate method somewhere as a before\_filter on the SiteController.  
I did the following:

redirects  
def radiant\_page\_request?  
! (params[:url] && params[:url].is\_a?(Array) &&  
(params[:url].include?(‘css’) || params[:url].include?(‘js’)))  
end

```
 c) In the custom extension file, I then do:
 SiteController.class_eval do
   include ContentManagement
   prepend_before_filter {|controller| controller.instance_eval

```

{authenticate\_custom\_user! if radiant\_page\_request?}}  
end

1. Once you do this, Devise will be set up to be used to authenticate  
against your end-user content. But it won’t work, because both Devise  
and Radiant inject a method named “authenticate” directly into the  
ApplicationController via module inclusion (luckily, they have different  
method signatures, or I would have had a tough time figuring that out).

I attempted to force the segregation of these two authenticate methods  
using nothing but fancy metaprogramming to try and change inheritance  
hierarchies and what-have-you. I don’t think that is possible,  
actually. Ultimately, I decided that the solution with the least  
customization (and thus, easiest to manage over time), would be to  
statically bypass the ApplicationController provided by Radiant in  
Devise. So…

1. Create a new controller named DeviseController that looks like:

class DeviseController \< ActionController::Base  
layout ‘devise’  
end

I put mine in my custom extension’s app/controllers directory, but you  
can put it anywhere as long as it is loaded before any of the Devise  
stuff.

Also, notice that I built a custom layout for Devise (devise.html.haml)  
that looks like my Radiant-managed layout for end-user content.

Yes, that means that changes to the layout within Radiant must be  
repeated in this layout file. However, I couldn’t figure out a good way  
to share the layouts (even using file\_based\_layout, I would have had  
significant duplication to deal with - I decided to go the simplest  
route). You can’t use radiant\_layout to share an existing Radiant  
layout since the Devise views are not rendered via SiteController.

1. Put a copy of the Devise gem into RAILS\_ROOT (or  
RADIANT\_ROOT)/vendor/gems

2. In vendor/gems/devise/app/controllers, change each of the five 5  
Devise controller’s class definitions so that they descend from  
DeviseController, instead of ApplicationController, like so:

class ConfirmationsController \< DeviseController

Note that each of the 5 controllers does:

include Devise::Controllers::InternalHelpers

and this is where the conflicting “authenticate” method comes from. But  
now, because there’s no more ApplicationController in the hierarchy,  
there is no conflict.

CAVEATS:

It is very important that the route file that pulls in the Devise route  
executes before you attempt to use any of the Devise “custom\_user”  
specific helpers. The route configuration is what creates all of the  
Devise helpers that are then included in various places. If you cause  
any helper files to be included before the Devise route is processed,  
none of the “custom\_user” helper methods will be available.

Wes

P. S. It would be interesting to see if it made sense to use Devise for  
all Radiant authentication (e.g. both end users and Radiant users), as  
Devise has authentication for different scopes baked in from the start.

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [October 27, 2010, 7:10am UTC](https://www.ruby-forum.com/t/using-devise-as-an-authentication-solution-for-end-users-with-radiant-updated/198065/2 "2010-10-27T07:10:31Z")

</div>

Thank you very much for that post, I’ve been looking for that solution  
to long time, I already did all those changes and now  
/custom\_users/sign\_up is working, I’m able to register, but the  
/custom\_users/sign\_in doesn’t work, I’m getting this error as soon as I  
push sign\_in button and the app is trying the authenticate process:

* * *

Processing SessionsController#create (for 127.0.0.1 at 2010-10-27  
01:07:50) [POST]  
Parameters: {“commit”=\>“Sign in”, “custom\_user”=\>{“remember\_me”=\>“0”,  
“password”=\>“calabaza”, “email”=\>“removed\_email\_address@domain.invalid”}}

ArgumentError (wrong number of arguments (1 for 0)):  
devise (1.0.8) [v] app/controllers/sessions\_controller.rb:19:in  
`authenticate' devise (1.0.8) [v] app/controllers/sessions_controller.rb:19:in`create’  
warden (0.10.7) lib/warden/manager.rb:35:in `call' warden (0.10.7) lib/warden/manager.rb:35:in`call’  
warden (0.10.7) lib/warden/manager.rb:34:in `catch' warden (0.10.7) lib/warden/manager.rb:34:in`call’

* * *

Do you have any idea about how to solve it? I will really appreciate any  
idea about that

Thank you very much for that post

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [October 27, 2010, 7:23am UTC](https://www.ruby-forum.com/t/using-devise-as-an-authentication-solution-for-end-users-with-radiant-updated/198065/3 "2010-10-27T07:23:07Z")

</div>

Did you segregate the Devise controllers away from the  
ApplicationController?

What you’re seeing is the collision between the Devise authenticate  
method and the LoginSystem (Radiant) authentication method.

You need to “vendor” Devise and change it’s controllers to descend from  
ActinController:Base instead of ApplicationController.

W

Sent from my iPhone

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [October 27, 2010, 7:57am UTC](https://www.ruby-forum.com/t/using-devise-as-an-authentication-solution-for-end-users-with-radiant-updated/198065/4 "2010-10-27T07:57:15Z")

</div>

Hi,

Thanks for the response,

yes, I already segregate the Devise controllers, I made a copy of devise  
gem at :  
/trunk/vendor/gems/devise-1.0.8, and I already change those 5  
controllers to something like:

class ConfirmationsController \< DeviseController

on each one

And I think is using that device gem in vendor, because that [v] that  
appears on the error lines:

devise (1.0.8) [v] app/controllers/sessions\_controller.rb:19:in  
`authenticate' devise (1.0.8) [v] app/controllers/sessions_controller.rb:19:in`create’

But still I’m getting the error, any other idea?

Thank you very much

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [October 27, 2010, 7:02pm UTC](https://www.ruby-forum.com/t/using-devise-as-an-authentication-solution-for-end-users-with-radiant-updated/198065/5 "2010-10-27T19:02:06Z")

</div>

That was the problem

Thank you very much Wes, it was because I didn’t have :

DeviseController inherits from ActionController::Base

that was:

```
 class DeviseController < ActionController

```

That should be :

```
  class DeviseController < ActionController::Base

```

Thank you very much for your help, now that is working very good,

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [October 27, 2010, 7:14pm UTC](https://www.ruby-forum.com/t/using-devise-as-an-authentication-solution-for-end-users-with-radiant-updated/198065/6 "2010-10-27T19:14:21Z")

</div>

Good. If you look at ApplicationController, you’ll see the very first  
thing it does is include the Radiant LoginSystem library, and that’s  
what collides with Devise.

class ApplicationController \< ActionController::Base  
include LoginSystem

Glad to hear it’s working.

Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [October 27, 2010, 5:06pm UTC](https://www.ruby-forum.com/t/using-devise-as-an-authentication-solution-for-end-users-with-radiant-updated/198065/7 "2010-10-27T17:06:12Z")

</div>

And the DeviseController inherits from ActionController::Base, right?

What is the before\_filter line that you’re using to authenticate through  
Devise?

Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [November 9, 2010, 5:07am UTC](https://www.ruby-forum.com/t/using-devise-as-an-authentication-solution-for-end-users-with-radiant-updated/198065/8 "2010-11-09T05:07:36Z")

</div>

Hi,  
thanks a lot for your post.

Did you have to run:  
ruby script/generate devise\_views  
or did you manage to add the views to the load path?

Without those views inside the extension I am getting a “Template is  
missing” when I submit the forgot password for example.

Ta,  
enrico
