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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:36:25+00:00 2026-06-14T09:36:25+00:00

I have a Rails 3.2.8 application with a model called Task. In my Task

  • 0

I have a Rails 3.2.8 application with a model called Task. In my Task model I have a datetime property called ‘complete_date’. When I try to view my complete_date in a view with..

<%= @task.complete_date.strftime('%b %e, %Y') %>

I get an error saying “undefined method `strftime’ for nil:NilClass”. However, the complete_date field is not null. The following query..

mysql> select count(*) from tasks where complete_date is null;

returns 0 rows. I can retrieve the complete_date, in the same view, with the following code…

<% @task.attributes.each_pair do |name, value| %>
    <% if name == "complete_date" %>
      <%= value.strftime('%b %e, %Y') %>
    <% end %>
<% end %>

This works perfectly, so it seems the problem is only with accessing the attribute with the dot notation (@task.complete_date). I have listed ‘complete_date’ as an attr_accessible and an attr_accessor in my Task model. Any idea why I am always getting nil when referencing the complete_date field with @task.complete_date? Thanks.

  • 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-14T09:36:26+00:00Added an answer on June 14, 2026 at 9:36 am

    You should remove attr_accessor :complete_date. Because attr_accessor creates two methods (#complete_date & #complete_date=) and uses the instance variable @complete_date, that is nil, because its not filled with the value of the record’s attribute. These two methods overrided ActiveRecord attribute accessor methods.

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

Sidebar

Related Questions

In a rails application, I have a number of attributes for a model called
I have a model in my rails application which is class Person < ActiveRecord::Base
I have an existing Rails 3.1 application with a model Products with price, description,
In my rails application I have two models called Kases and Notes. They work
In my application I have an extended User model called UserProfile. This user can
In my rails application my models have a to_html method. This method is called
In my Rails 3 application I have a simple model relationship which is as
I have a project model in my rails 3.1 application and I want to
I have a relationship table in a rails application called edit_privileges , in which
I have an application in Rails 3.2.1 with a model which has a column

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.