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

  • SEARCH
  • Home
  • 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 7730425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:13:16+00:00 2026-06-01T06:13:16+00:00

I have the following abilities model: class Ability include CanCan::Ability def initialize(user) user ||=

  • 0

I have the following abilities model:

class Ability
  include CanCan::Ability

  def initialize(user)
    user ||= User.new # guest user, not logged in.

    if user.role? == :admin
      can :manage, :all
    else
      can :read, :all
      end
      if user.role == "default"
        can :create, Homescreen
        end
        can :destroy, Homescreen do |homescreen|
          homescreen.try(:user) == user
      end
  end
end

And I have the following users model:

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  before_create :setup_default_role_for_new_users


  attr_accessible :email, :password, :password_confirmation, :remember_me
  has_many :homescreens

  ROLES =%w[admin default]
  private
  def setup_default_role_for_new_users
    if self.role.blank?
      self.role = "default"
    end
  end
end

When I run it on my local machine, it works fine.

However, when I deploy to heroku, I get the following error:

GET URL.herokuapp.com dyno=web.1 queue=0 wait=0ms service=158ms status=500 bytes=643
   app/models/ability.rb:7:in `initialize'
 NoMethodError (undefined method `role?' for #<User:0x00000003b56050>):

 cache: [GET /] miss

 Started GET "/" for my-ipaddress at 2012-03-19 16:14:38 +0000

 NoMethodError (undefined method `role?' for #<User:0x00000003df5d88>):
   app/models/ability.rb:7:in `initialize'

 cache: [GET /] miss

What am I doing wrong?

  • 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-01T06:13:18+00:00Added an answer on June 1, 2026 at 6:13 am

    I restarted heroku with the following command:

    heroku restart && heroku ps:restart

    It then worked fine.

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

Sidebar

Related Questions

I have following setup. from django.db import models from django.contrib.auth.models import User class Event(models.Model):
I'm using Cancan to control User abilities, and have recently run into an odd
I have the following: User model that has_and_belongs_to_many Restaurants and vice-versa. Restaurant model that
The following function should ensure that if a device does not have CSS3 abilities
I have following class public class ButtonChange { private int _buttonState; public void SetButtonState(int
I have following simple class: @interface Article: NSObject { NSString *title; } @property (copy,
I have following implementation public abstract class BaseAcion extends ActionSupport { private String result;
I have following structure of an HTML document: <body> <div class=main> <div class=left></div> <div
Have following String built SQL query: StringBuilder querySelect = new StringBuilder(select * from messages
I have following code: public class reader extends Activity { WebView mWebView; String mFilename;

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.