Question

Im having a weird problem on heroku, this is the error I get:

Im using rails 3.2.8, ruby 1.9.3, with active admin, friendly id!

/app/app/models/user.rb:2:in `<class:User>': uninitialized constant User::FriendlyId (NameError)

On my local environment, also using postgres, everything works fine...

Heres my user model

class User < ActiveRecord::Base
  extend FriendlyId
  after_initialize :set_username
  before_create :set_as_student

  friendly_id :username, use: :slugged

  ROLES = %w[admin coordinator student]

  # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable,
  # :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  # attr_accessible :title, :body
  attr_accessible :email, :password, :password_confirmation, :remember_me,
                  :name, :code, :phone, :roles

  def roles=(roles)
    self.roles_mask = (roles & ROLES).map { |r| 2**ROLES.index(r) }.inject(0, :+)
  end

  def roles
    ROLES.reject do |r|
      ((roles_mask || 0) & 2**ROLES.index(r)).zero?
    end
  end

  def role?(role)
    roles.include? role.to_s
  end

  def self.search(query)
    where do
      ((name =~ "%#{query}%") | (code =~ "%#{query}%"))
    end
  end

  def should_generate_new_friendly_id?
    new_record?
  end

  private
  def set_username
    self.username = self.email.split('@')[0]
  end

  def set_as_student
    self.roles=(['student'])
  end

end

I believe it has to do something with friendly_id but I don't know whats wrong, Ill appreciate the help a lot!

Thank you all.

Was it helpful?

Solution

You need to have friendly_id in your Gemfile out of groups such as :assets otherwise in production mode (which runs without the assets group) it can't be found.

Debugged over at https://github.com/norman/friendly_id/issues/326

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top