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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:37:32+00:00 2026-06-08T12:37:32+00:00

So I think I’m close to getting the right syntax on the method below,

  • 0

So I think I’m close to getting the right syntax on the method below, but I’m not quite these. I always get confused as to when to use the “self” method. Here’s the context: the method below is meant to compare a file saved to the database against a file currently on a website. The method itself is a member of a model class in a rails app.

But when I run the code in the console, it gets stuck on the “self.” It can’t call the versions method on a nil class. What am I misunderstanding about the “self”? What do I need to do to make this method work?

    def compare
      live_file = download_file
      archive_file = self.versions.last.changeset[:robots_file]
      if live_file != archive_file
        return mismatch
      end 
    end

Edit: Here’s the error message I get in console.

NoMethodError: undefined method `versions' for nil:NilClass
from /Users/bendowney/sites/WatchApp/app/models/site.rb:14:in `compare'
from (irb):50
from /Users/bendowney/.rvm/gems/ruby-1.9.3-p194@WatchApp/gems/railties-3.2.5/lib/rails/commands/console.rb:47:in `start'
from /Users/bendowney/.rvm/gems/ruby-1.9.3-p194@WatchApp/gems/railties-3.2.5/lib/rails/commands/console.rb:8:in `start'
from /Users/bendowney/.rvm/gems/ruby-1.9.3-p194@WatchApp/gems/railties-3.2.5/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

EDIT: Answer is below.

  • 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-08T12:37:34+00:00Added an answer on June 8, 2026 at 12:37 pm

    You all ask the right questions. They got me thinking. I made two changes to my original method and now it works. I needed to save the file I downloaded (line 2 below) and I had a forgot to encapsulate my “mismatch” status in quotation marks. Thanks for your help!

    def compare
      live_file = download_robots_file
      self.save
      archive_file = self.versions.last.changeset[:robots_file]
      if live_file != archive_file
        return "mismatch"
      end 
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think they are same thing but my boss say that is not right.
I think I am not getting something right with JMS and JTA. I am
I think this has probably been asked, but after reading a lot, I'm not
I think this is a simple SQL query problem, but I am just not
I think this should be straightforward, but with NHibernate simple things are always the
I think that handlers in android are tools to get different objects that are
I think I have a basic understanding of this, but am hoping that someone
I think this could be a very easy question for you. But I have
I think that asking this might be kind of silly but I'm still wondering
I think I have found a bug when setting or getting the Me.Top property

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.