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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:39:51+00:00 2026-05-21T19:39:51+00:00

I have an app that tracks a net worth on a balance sheet for

  • 0

I have an app that tracks a net worth on a balance sheet for a client. There is a client model which has many balancesheets, a balancesheet model which belongs to a client, and each balancesheet has many assets and many liabilities (nested). On the show page for the balancesheet it lists the assets, liabilities, and a total net worth. Right now balancesheets are ordered by entering a quarter (1,2,3 or 4) and the year. So each client ends up having balancesheets listed as Q1 2010, Q2 2010 and so on.

What I want to do is to compare the asset, liability, and net worth totals on any given balancesheet show page with the previously entered balancesheet for that client. This could be from last quarter or last year, as long as it’s the previous entry.

How do I do this?

UPDATE Okay, so on a more simple model (my client model) I figured out the basics to show the next or previous client name in the list:

def nextname
    self.class.
    order( "id" ).
    where( "id > :id", attributes.symbolize_keys).first
end

The only problem with this is when it gets to the last client in the table, it returns the error:

undefined method `name’ for nil:NilClass
Extracted source (around line #37):

37: <%= @client.nextname.name %>

What do I need to write in order to return something blank where there isn’t another record?

  • 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-05-21T19:39:52+00:00Added an answer on May 21, 2026 at 7:39 pm

    You should always be weary of calling methods on things that may not be defined. This has always been a problem that has suggested many solutions, each of which has its various merits.

    In this case what you should do is write a helper method to avoid complicating your view, and make a model method that is more specific in what it does.

    def next
      self.class.order("id").where("id>?", self.id).first
    end
    

    In your helper you would create a method like this:

    def name_for_client(client)
      client and client.name
    end
    

    In your case you would use it like this:

    <%= name_for_client(@client.next) %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my asp.net mvc app I have a Log object which tracks what happens
My rails app has a simple model Links which tracks all the Urls associated
I have a web app that will draw a polyline for each user (tracks
Have an app that has listings - think classified ads - and each listing
I have an asp.net/C# app that uses subversion for source control. My app automatically
I have an iPad app that submits orders to an ASP.NET MVC web site
In my current .NET and FBML-based facebook app, I have some code that looks
I have an ASP.NET application which tracks statistics by creating and writing to custom
So I have a .NET app which goes thru and generates a series of
I have an app that tracks wildlife where the user enters data based on

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.