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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:05:45+00:00 2026-06-10T17:05:45+00:00

This has got to be extremely simple but I’m banging my head against the

  • 0

This has got to be extremely simple but I’m banging my head against the wall trying to find an answer. I want to find the last updated record using the instance method shown below.

class Subject < ActiveRecord::Base
  has_many :assignments, :dependent => :destroy

  def get_last_assignment_date 
    @last_date = self.assignments.select("date_assigned").last
    @last_day = @last_date.wday
  end

Where my assignments model looks like this:

create_table "assignments", :force => true do |t|
t.date     "date_assigned"
<snip>

But Rails returns the following error for get_last_assignment_date:

undefined method `wday' for #<Assignment date_assigned: "2012-08-30">

I need to convert the value returned by active record to a Time format that Ruby can handle but I can’t figure out how to do it and it seems to be so easy that no one has even bothered to write how to do it. I would greatly appreciate it if someone could point me in the right direction.

  • 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-10T17:05:46+00:00Added an answer on June 10, 2026 at 5:05 pm

    This:

    self.assignments.select("date_assigned").last
    

    returns an Assigment object, not a Time object.

    So, instead of:

    @last_day = @last_date.wday
    

    you have to do:

    @last_day = @last_date.date_assigned.wday
    

    You may be aware of this, but just in case: select("date_assigned").last doesn’t give you the latest date. You have to use order:

    self.assignments.order(:date_assigned).last
    

    Of course if the most recently created object is also the one with the latest date_assigned then it doesn’t matter.

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

Sidebar

Related Questions

I'm sure this has got a simple answer, but it's stumping me :( I'm
I want to achieve the functionality that this editor has got with its preview
I've been working on some MySQL Joins but this one has got me a
This has got to be easy, but has got me stumped. How do I
This has got to be something simple: I set up a frames page with
This has got to be simple -- surely this method is supposed to work
This has got to be an easy thing to do, but I think that
Ok, this has got to be a super simple problem. I just can't seem
This has got to be obvious but I'm just not seeing it. I have
Perhaps I do not understand correctly how MVC Areas work, but this has got

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.