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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:16:41+00:00 2026-06-17T00:16:41+00:00

I have the following helper method that I’m using to upload some records to

  • 0

I have the following helper method that I’m using to upload some records to Dropbox. For each of the three models (logbooks, aircraft, and approaches), I’m doing the exact same thing. I’d like to make this more DRY and only have the code once, but I don’t understand how to reference a model in an abstracted way.

Any recommendations?

#------------------------------------------------------------
# Upload entries to Dropbox
#------------------------------------------------------------
def upload_items(items, folder, client)

  # Go through each item and upload it to Dropbox
  items.each do |item|

    if folder == 'logbook'
      # Get the file from the database to upload
      @logbook = current_user.logbooks.find_by_sync_id(item)
      # Upload it
      uploaded_file = client.put_file("/logbook/#{item}.json",@logbook.to_json, overwrite = true)
      # Reset the updated_flag in the database
      @logbook.update_attributes(updated_flag: 0)

    elsif folder == 'aircraft'
      # Get the file from the database to upload
      @aircraft = current_user.aircrafts.find_by_sync_id(item)
      # Upload it
      uploaded_file = client.put_file("/aircraft/#{item}.json",@aircraft.to_json, overwrite = true)
      # Reset the updated_flag in the database
      @aircraft.update_attributes(updated_flag: 0)

    elsif folder == 'approaches'
      # Get the file from the database to upload
      @approach = current_user.approaches.find_by_sync_id(item)
      # Upload it
      uploaded_file = client.put_file("/approaches/#{item}.json",@approach.to_json, overwrite = true)
      # Reset the updated_flag in the database
      @approach.update_attributes(updated_flag: 0)

    end
  end
end

Ruby 1.9.3, Rails 3.2.8

  • 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-17T00:16:43+00:00Added an answer on June 17, 2026 at 12:16 am

    This will do the job.

    The critical part below is current_user.public_send(folder.to_sym) which takes the folder name and converts it to a message to send to the current_user.

    #------------------------------------------------------------
    # Upload entries to Dropbox
    #------------------------------------------------------------
    def upload_items(items, folder, client)
    
      # Go through each item and upload it to Dropbox
      items.each do |item|
        # Get the file from the database to upload
        resource = current_user.public_send(folder.pluralize.to_sym).find_by_sync_id(item)
        # Upload it
        uploaded_file = client.put_file("/#{folder}/#{item}.json",resource.to_json, overwrite = true)
        # Reset the updated_flag in the database
        resource.update_attributes(updated_flag: 0)
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a helper method that looks something like the following: private D
I have the following helper method that returns the value from a field. public
I currently have a class file with the following enumeration: using System; namespace Helper
I have some code that looks like the following. First I have some domain
In this response, I came up with the following helper method that could be
I have a razor helper method that needs to take in a Func<> that
I have a helper method called get_books_from_amazon that does an API call and returns
I have the following code inside a helper in rails: def custom_options_tag(opts={}) ['am', 'pm'].each
I have the following code in a Rails 3.2.1 helper that keeps escaping HTML
I have a button_to helper method in a view table that I cannot get

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.