I have an association for the user as user has_many agents and agent belongs_to user . in the rails console , I'm trying to use different users to test a specific scenario, and I want the user to have no agents, so I want to remove user.agents . I tried user.agents.map(&:destroy) , but it gives an error like ActiveRecord::StaleObjectError: Attempted to delete a stale object .i even tried user.agents.delete_all , but it doesn't work either. I can remove user agents with a single command in the rails console.
ruby ruby-on-rails ruby-on-rails-3 rails-console
user2164011
source share