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 8830195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:01:01+00:00 2026-06-14T08:01:01+00:00

I have the following model in my /app/models folder: class MyModel < ActiveRecord::Base require

  • 0

I have the following model in my /app/models folder:

class MyModel < ActiveRecord::Base
  require "dashboard"
  extend Dashboard
  
# ...
end

I then have in my /lib folder a file named dashboard.rb, which has the following code:

module Dashboard
  def self.my_function
    # --> My question pertains to what I need to put here...
  end
end

I’d like to write a line of code in MyModel::Dashboard.my_function so that it will return the name of my model (in this case MyModel).

I did find some information on Get class name from a module and https://gist.github.com/1014971, but it seems like when my model inherits from ActiveRecord::Base, it’s different. The latter of these articles supposedly explains this, but I’m at a loss.

I tried some permutations with superclass.name from within Dashboard.my_function, but I just get Dashboard or Module returned, and not MyModel.

Anyone who can shed light on how to do this would be greatly appreciated.

  • 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-14T08:01:02+00:00Added an answer on June 14, 2026 at 8:01 am

    By using extend, you are making the module methods class methods of your MyModel class. Try this:

    module Dashboard
      def my_function
        self.name
      end
    end
    
    
    class MyModel < ActiveRecord::Base
      require "dashboard"
      extend Dashboard
    
      # ...
    end
    

    And rather than calling it as MyModel::Dashboard.my_function you would just call it directly on your model class -> MyModel.my_function would return MyModel

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

Sidebar

Related Questions

I have the following models. # app/models/domain/domain_object.rb class Domain::DomainObject < ActiveRecord::Base has_many :links_from, :class_name
I have the following model in my Django app: class Group(models.model): name=models.CharField(max_length=30) users=Models.ManyToManyField(User) In
In my Django App I have the following model: class SuperCategory(models.Model): name = models.CharField(max_length=100,)
I have an existing app with the following model class Contact(models.Model): lastname = models.CharField(max_length=200)
In my GWT app I have the following model class: import com.google.gwt.user.client.rpc.IsSerializable; public class
I have the following model structure: class Container(models.Model): pass class Generic(models.Model): name = models.CharacterField(unique=True)
I have the following model and instance: class Bashable(models.Model): name = models.CharField(max_length=100) >>> foo
I have the following model: class User: name = models.CharField( max_length = 200 )
I have the following view within an app called 'manager': class AddObj(CreateView): model =
I have the following two models: class Provider(models.Model): provider = models.CharField(max_length=100, unique=True) class UserProfile(models.Model):

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.