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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:46:56+00:00 2026-06-06T11:46:56+00:00

In my code, admins can add users and assign them jobs. If the admin

  • 0

In my code, admins can add users and assign them jobs. If the admin decides to delete a user, I want to check for any jobs that the user may be assigned to and update its assignment to the admin. Since the user deletion is taking place in my user_controller and calling Jobs, is this the best way? If not, could you please advise as to the most efficient way to do this is, especially if the user is assigned to 1-N jobs? Thanks in advance.

users_controller.rb

 def destroy
     if admin?
       jobs = Job.where("user_id = ?", params[:id]) #find jobs where user is that being deleted
       jobs.each do |job|         
        job.update_attribute(:user_id, current_user.id)  #for each job set the user_id to the admin_id
       end     
    end
    redirect_to users_url
  end
  • 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-06T11:46:58+00:00Added an answer on June 6, 2026 at 11:46 am

    You can use the #update_all method to only execute one SQL query:

    Here we will update all jobs with user_id of @user.id, set user_id to current_user.id

      def destroy
        @user = User.find(params[:id])
        if admin?
          Job.update_all {user_id: current_user.id}, {user_id: @user.id} 
        end
        @user.destroy
        redirect_to users_url
      end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to implement asp.net role provider to assign users over my LAN to
Here is an abstract example: 2 types of users ( user and admin )
I want to write a Console application which will just add a new User
I am looking for a web based svn admin that can use LDAP Users
I want to add functionality to check session ao. I created one function like
the following code fieldvalue = Admin::FieldValue.where(:item_id => @admin_item.id, :field_id => key) fieldvalue.update_attributes(:value => value)
The code is mongoengine.connect('admin', host='xxx.dotcloud.com', port=16333 , username='root', password='pass') and it shows the error
With the following code I get all the pages I admin on Facebook using
I have this PHP code in a loop for every post on the admin
I use below code to post an url to facebook page as a admin

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.