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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:16:13+00:00 2026-06-11T12:16:13+00:00

My app is supposed to allow users to create a status_update, that draws info

  • 0

My app is supposed to allow users to create a status_update, that draws info from a previous status_update through a method called ‘previous_status_update”.

Within my view I have this code:

<span> <%= status_update.current_weight - status_update.previous_status_update.current_weight %></span> 

Within my model I have this corresponding code:

after_find :previous_status_update  

 def previous_status_update
 current_id = self.id
 previous_status_update = user.status_update.where( "created_at < ? ", self.created_at ).first
end  

within the console the following commands, in order, work perfectly:

user = User.find_by_id(3)
#<User id: 3, email: "example-3@r

status = user.status_update.first
#<StatusUpdate id: 73, created_at: "2012-09-13 23:08:35",......

status.previous_status_update
#<StatusUpdate id: 68, created_at: "2012-09-13 23:08:35".....

prev_stat = status.previous_status_update
prev_stat.current_weight 
=> 168

I’m guessing the problem is that the model isn’t placing the active record object into an instance variable that can be called upon like an object. Instead I simply have a method call that returns the active record object but isn’t in a form that can be called for attributes.

I don’t think I can store the entire object in a database column called “previous_status_update”…


I think that another possibility for this error is that it is pointing to the first entry in the sample data which does not have a previous status update. So when the program tries to come up with a value it simply returns nil. I think this is what the error is referring to.

So really, what I need is for rails to chill out with that exception.

  • 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-11T12:16:14+00:00Added an answer on June 11, 2026 at 12:16 pm

    The way I solved this was by returning the first status update it’s self for the non existing ‘previous’ status update.

    This fixed the issue.

    Here is what the method looks like:

     def previous_status_update
     previous_status_update = user.status_update.where( "created_at < ? ", self.created_at ).first   
     if previous_status_update == nil
       return self
     else
       previous_status_update
     end
    end    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello All I am writing some software that will allow users to create their
I've got an iPhone App that is supposed to send POST data to my
I have a widget that supposed to call an Activity of the main app
Consider the following situation: - Suppose my app allows users to create the states
We are using SVG in our web app and we need to allow users
I have this app of mine that contains a section that will allow the
I'm currently trying to make a form called countcash that allows users to input
So my simple idea is to create an app that allows the user to
I am developing an iPhone app that uses Facebook Connect to identify users. Everything
I am currently developing an Android app that is supposed to inform the user

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.