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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:46:49+00:00 2026-05-26T07:46:49+00:00

Going mad here. Any pointers gratefully received! I’ve got a Delivery model and I’m

  • 0

Going mad here. Any pointers gratefully received!

I’ve got a Delivery model and I’m trying to add a method to update the delivery state, based on delivery lines. This function is defined within the model class, and delivery_state is one of the model attributes:

def updateDeliveryState
  expectedLines = DeliveryLine.where( :delivery_id => id,
                                      :line_state => 'EXPECTED' )
  logger.debug "State1: #{delivery_state}"

  if expectedLines.length == 0
    if delivery_state == 'EXPECTED' || delivery_state == 'RECEIVING'
      delivery_state = 'RECEIVED'               # commenting this line fixes it
      save
    end
  else
    logger.debug "State2: #{delivery_state}"
    if delivery_state == 'EXPECTED'
      logger.debug "Updating to receiving"
      delivery_state = 'RECEIVING'
      save
    end
  end
end

What I’m seeing in the log is that between the 2 logger.debug lines, the delivery_state has been cleared:

State1: EXPECTED
DeliveryLine Load (4.5ms)  SELECT "delivery_lines".* FROM "delivery_lines" 
WHERE "delivery_lines"."line_state" = 'EXPECTED' 
AND "delivery_lines"."delivery_id" = 227
State2:

If I comment out the line marked in the above code, it appears to work OK:

State1: EXPECTED
DeliveryLine Load (9.6ms)  SELECT "delivery_lines".* FROM "delivery_lines" 
WHERE "delivery_lines"."line_state" = 'EXPECTED' 
AND "delivery_lines"."delivery_id" = 227
State2: EXPECTED
Updating to receiving

However, I can see after refreshing that the delivery is still EXPECTED after this??

  • 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-26T07:46:50+00:00Added an answer on May 26, 2026 at 7:46 am

    To elaborate on my comment: it seems like you are creating a local variable in the if. Look:

    class Foo
      attr_accessor :bar
    
      def test
        unless bar
          bar = 1
        end
      end
    end
    
    f = Foo.new
    f.test
    puts f.bar # empty line, bar is nil
    

    Now let’s make sure we call the setter:

    class Foo
      attr_accessor :bar
    
      def test
        unless bar
          self.bar = 1
        end
      end
    end
    
    f = Foo.new
    f.test
    puts f.bar # prints 1
    

    See: Why do ruby setters need “self.” qualification within the class?

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

Sidebar

Related Questions

I have been going mad trying to figure out why my scripts weren't working,
OK, so I think I'm going mad here! Here's where I am. SQL Server
I'm developing a site in Drupal 6, and I'm going mad trying to work
Im going mad trying to figure out why the title link (in the left)
Please save me from going totally mad here. With my project, I keep finding
I'm going slidely mad over here, maybe someone can help me figure out what's
I'm going mad with the following problem which does not happen on any other
I am going mad trying to find an example of file upload code in
Please help with this issue, I'm going mad... I'm trying to make a client-server
Going mad now. I have a MVC solution that i've upgraded from MVC 1

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.