Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8761607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:19:29+00:00 2026-06-13T15:19:29+00:00

I do have this famous error : undefined method `current_user’ with declarative authorization, though

  • 0

I do have this famous error : “undefined method `current_user'” with declarative authorization, though I set up this variable in the application_controller.rb :

class ApplicationController < ActionController::Base
  protect_from_forgery
  before_filter :set_current_user

  protected

    def set_current_user
      Authorization.current_user = current_admin_utilisateur
    end
end

I’m using a table called “admin_utilisateurs” instead of “users”. Which was activated in Devise with : “rails generate devise admin_utilisateur”

Devise is working great.

For info, I customized my users table (admin_utilisateurs) with “roles_model” gem, So that I do have an attribut roles_mask that allows me to manage different roles while providing a role_symbols method for declarative authorization.

The problem is now that I got this strange error though the Authorization.current_user is set by the application_controller.rb.

This is the begning of one my resource controllers that procude the error :

class PubResponsablesController < ApplicationController

  before_filter :authenticate_admin_utilisateur!
  filter_resource_access

  ...
end

I search by google for this error, but none of the results provide a working solution.
Could anybody help me on this ?

Many Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T15:19:31+00:00Added an answer on June 13, 2026 at 3:19 pm

    Ok this is the final answer.

    I modified my app/controller/application_controller.rb because I don’t use the @current_user instance variable in the views :

    class ApplicationController < ActionController::Base
      protect_from_forgery
    
      # This is mandatory if you want to secure as well your app/models
      before_filter :set_current_user
    
      # This method is required by declarative_authorization on every controller
      #  that is using filter_resource_access (or any other declarative_auth.. mechanism)
      def current_user
        current_admin_utilisateur
      end
    
      protected
    
      def set_current_user
        Authorization.current_user = current_admin_utilisateur
      end
    end
    

    As I said I’m using the following gem in collaboration :

    gem devise for the authentication
    The user-model-name is “admin_utilisateur” instead of “user”, but it could have been : account, member, group or what you need.

    gem role_model to provide a brillant role method “role_symbols” to my user model
    *The method role_symbols was returning a “Set” subclass instead of an “Array” but after quick post on Github, the developer (martinrehfeld) fixed this compatibility issue in a lightning matter of minutes. Great !*

    gem declarative_authorization to provide access management based on roles.
    My will to use a different model name than “user” is confirmed to work by the following post.

    The only thing that declarative_authorization needs is the current_user method on each controller. As I’m using a different model name with Devise (such as admin_utilisateur, account, member, …) the helper created by devise have a different name. Instead of current_user, it is current_admin_utilisateur (or current_account, current_member). So I have to create my own current_user method.

    The role_symbols method required by declarative_authorization is provided by role_model gem.

    I hope this will help other developer cause I spent two days to sort out how all this fabric works together. Devise took me even more with routing issues.

    My few cents to RoRrrr 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this form: <%= form_tag posts_path, :method => :get, :class => search_nav do
I have this class: Class B { private String D; private String E; }
i know that this is a famous question and have been asked many times.
I get the famous out of memory error. But i have tried many of
I have the famous error address already in use because I have no check
Have this query: SELECT HOUR( DATE ) AS hr, COUNT( * ) AS cnt
Have this self-made slider: http://jsfiddle.net/wyc3P/4/ What it does: takes min and max values in
I have this string 2012-06-27 16:17:06 and I want to convert it to GMT
I have this application where I implement the ActionBar Fragment interface. Underlying the interface,
I have this form, in which i need to populate a combo box with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.