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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:26:45+00:00 2026-05-26T00:26:45+00:00

I have a generic import table that allows the loading of csv files into

  • 0

I have a generic import table that allows the loading of csv files into different columns in my import table. The same import table is used for multiple types of imports, so I don’t process the individual fields until the user is ready and tells me where to process it.

So in this case I have an import table with many cells that I will use to create (or update) donors in my donors table. How do I send my import_table data associated with the import_table model and controller to the create method of my donors_controller?

the create method of my donors_controller:

      def create
        # need to find donor by id if given, else use find_or_create_by_blahblahblah
        unless @donor = Donor.find_by_id(params[:donor][:id])
          @donor = Donor.find_or_initialize_by_company_and_prefix1_and_first_name1_and_last_name1_and_address1(params[:donor])
        end

        if @donor.new_record?   

          respond_to do |format|
            if @donor.save
              format.html { redirect_to @donor, notice: 'Donor was successfully created.' }
              format.json { render json: @donor, status: :created, location: @donor }
            else
              format.html { render action: "new" }
              format.json { render json: @donor.errors, status: :unprocessable_entity }
            end
          end    
        else
          respond_to do |format|
            if @donor.save
              format.html { redirect_to @donor, notice: 'Donor already exists.  Please edit donor if needed.'}
              format.json { render json: @donor, status: :created, location: @donor }
            else
              format.html { render action: "new" }
              format.json { render json: @donor.errors, status: :unprocessable_entity }
            end
          end 
        end   

      end

Then in my import_tables controller I have this method:

def process_import
  @import = ImportTable.find(params[:id])
  if @import.import_type == 'Prospects'
     #do something here....
  elsif @import.import_type == 'Donations'
     #do something here...
  end

end

I am not sure what exactly I should do in the #do something here... parts.

I was thinking I should pick out the right columns from @import and put them in [:donor] array and send them to the create method of my donors_controller, but I am not sure exactly how to do that or if that is the right way to go about 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-26T00:26:46+00:00Added an answer on May 26, 2026 at 12:26 am

    The missing link is that you need to get to the Class from it’s name..

    There are several ways to do this, e.g. with an “eval’ , but a cleaner and simpler way to do this is to:

    # do something:
      class_name = @import.import_type
      klass = ActiveRecord.const_get(class_name)  # now you have a reference to your class
    
      #... then do whatever you like with your symbolic klass, e.g. create your new entry
      #  klass.find_or_create(...) , klass.find(1), klass.first ,
      #  klass.create( {attributes for new instance of klass} )
    

    this works so conveniently because in your model you do YourClass < ActiveRecord::Base ,
    your class is part of the ActiveRecord module, Classes in Ruby are constants which are stored in the context in which they are defined (=in their module), therefore you can query that context, e.g. ActiveRecord, and find your class.

    If your class was not derived from ActiveRecord::Base , you could still do a:

     klass = Kernel.const_get( class_name )
    

    see also:
    http://infovore.org/archives/2006/08/02/getting-a-class-object-in-ruby-from-a-string-containing-that-classes-name/

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

Sidebar

Related Questions

I have a need to import a number of CSV files into corresponding tables
I have a web service that looks like this [WebMethod] public int Import(System.Collections.Generic.List<Record> importRecords)
I have generic type that looks like: public class GenericClass<T, U> where T :
Is there any name for the following DB table design: Basically we have generic
I have a generic class that should allow any type, primitive or otherwise. The
I have a generic class that I'm trying to implement implicit type casting for.
Hey there. I have a c# application that parses txt files and imports the
In this simplified example I have a generic class, and a method that returns
I have a list of text files file1.txt, file2.txt, file3.txt .. filen.txt that I
I have an iphone app that uses table view as the interface. Each time

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.