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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:37:56+00:00 2026-06-17T22:37:56+00:00

class Task < ActiveRecord::Base attr_accessible :due_date, :text def self.this_week where(:due_date => Date.today.beginning_of_week..Date.today.end_of_week) end end

  • 0
class Task < ActiveRecord::Base
  attr_accessible :due_date, :text

  def self.this_week
    where(:due_date => Date.today.beginning_of_week..Date.today.end_of_week)
  end
end

class Important < ActiveRecord::Base
  attr_accessible :email

  has_one :task, :as => :taskable, :dependent => :destroy

  delegate this_week, :to => :task
end

So far this delegate is not working as expected, when I try Important.this_week. I get an error saying there is no method this_week defined for class…

Any ideas? Can I even delegate to a class method like this? I may have another class or two extending Task in this way, so I’m curious how this works in a way that doesn’t duplicate a bunch of code to each implementing class.

  • 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-17T22:37:58+00:00Added an answer on June 17, 2026 at 10:37 pm

    You’re picking up the ActiveSupport delegation core extension. The delegate helper defines an instance method for the current class so that instances of it delegate calls to some variable on that instance.

    If you want to delegate at the class level, you need to open up the singleton class and set up the delegation there:

    class Important < ActiveRecord::Base
      attr_accessible :email
    
      has_one :task, :as => :taskable, :dependent => :destroy
    
      class << self
        delegate :this_week, :to => :task
      end
    end
    

    But this assumes that Important.task is a reference to the Task class (which it is not)

    Rather than relying on the delegation helper, which is just going to make your life difficult, I’d suggest explicit proxying here:

    class Important < ActiveRecord::Base
      attr_accessible :email
    
      has_one :task, :as => :taskable, :dependent => :destroy
    
      class << self
        def this_week(*args, &block)
          Task.this_week(*args, &block)
        end
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Two models: class Task < ActiveRecord::Base has_many :subtasks end class Subtask < ActiveRecord::Base belongs_to
I have the following: class Person < ActiveRecord::Base has_many :tasks end class Task <
I have this Task model: class Task < ActiveRecord::Base acts_as_tree :order => 'sort_order' end
I defined the next things: task.rb : class Task < ActiveRecord::Base belongs_to :worker attr_accessible
Use case: class MyTask(Task): queue = 'default_queue' def run(self): # do work Normally I
I have two models, Developers and Tasks, class Developer < ActiveRecord::Base attr_accessible :address, :comment,
I have a simple model class Task < ActiveRecord::Base validates :deadline, :if => :deadline_in_future?
Let's say I have a simple model: class Subscription < ActiveRecord::Base attr_accessor :subscribed def
I have four models in my application, defined as follows class User < ActiveRecord::Base
I've got a class called Task. The header file goes as such: class Task

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.