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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:11:00+00:00 2026-05-24T03:11:00+00:00

I have a very painful issue here, if some one could help ? I

  • 0

I have a very painful issue here, if some one could help ?

I have a class Task with attributes and I wanted to make a bang method (because I’m changing the receiver) but I’m not able to change object attributes properly :

def reject!
    return nil if self.previous_owner.nil?
    self.delegate = false

    # Before, owner equal a User object
    self.owner = self.previous_owner # previous_owner is also a User object, but different
    self.previous_owner = nil

    return self if self.save
    raise "Can't save object"
end

This won’t work because self.owner will be nil…
I know this is because telling Ruby that self.owner = self.previous_owner and then changing self.previous_owner to nil.

So how can I avoid this ? I tried clone and dup method, but I’m not sure I want to have a new copied User object…

Strange thing too, if I try this in rails console :

a = 'Foo'
b = a
a = 'New value'

puts a # "New value"
puts b # "Foo"

So I think I’m missing something…

  • 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-24T03:11:01+00:00Added an answer on May 24, 2026 at 3:11 am

    Please note that self.owner and self.previous_owner are convenience methods provided by Rails. The actual fields should be called something like owner_id and previous_owner_id and contain the actual id of the User you want to link to.

    So a simpler, and failsafe approach is to write

    self.owner_id = self.previous_owner_id
    self.previous_owner = nil # this will unlink the previous owner
    self.save!
    

    and self.save! will raise if the save fails.

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

Sidebar

Related Questions

I have a very painful library which, at the moment, is accepting a C#
It's very painful to add multiple tickets to Trac or to have it as
We have very strange problem, one of our applications is continually querying server by
I have very simple window where I have 2 buttons - one for cancel,
I have very little experience with ASP.NET and I am doing some self-training before
I have been given the painful task of writing a C# application to sync
I have a very painful slow script that gets lots of data from MySQL
I have very simple question. In my application I have some TextEdit fields. I
I have very basic QT application (just create to explain my problem). So here
I have very strange behaviour of Java Date class: System.out.println(new Date().toGMTString()); long l =

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.