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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:30:36+00:00 2026-05-27T09:30:36+00:00

I have a controller like this: def download_link #It starts a background process to

  • 0

I have a controller like this:

def download_link
  #It starts a background process to handle all these things
  temp_file = Tempfile.new 'temp_file'
  temp_sqlite_db = SQLite3::Database.new temp_file.path

  temp_sqlite_db.execute("CREATE TABLE inspection (id INTEGER NOT NULL,desc VARCHAR(255));")
  inspections = Inspection.a_heavy_query_that_doesnt_worths_to_wait_so_much_for_a_reply
  # Some code inserting records and creating tables, with execute() too 
  # more code, compressing the db and sending an email with a download link to the zip file
end

Now, I would like to know if there’s a way to replace the execute() function and maybe create the tables and save records like inspection.create(something) . Thanks in advance

  • 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-27T09:30:37+00:00Added an answer on May 27, 2026 at 9:30 am

    If anyone needs something similar, this was my implementation:

    # config/initializers/sql_returner.rb
    module ActiveRecord
      class Base
    
        def sql_insert
          if attributes_with_quotes.empty?
            connection.empty_insert_statement(self.class.table_name)
          else
            "INSERT INTO #{self.class.quoted_table_name} " +
            "(#{quoted_column_names.join(', ')}) " +
            "VALUES(#{attributes_with_quotes.values.join(', ')});"
          end
        end
    
        def self.sql_create
          "CREATE TABLE #{table_name} (" +
          " #{ self.columns.collect{ |column|
            column_sql = " #{ column.name }  #{ sql_type column } "
            column_sql << " PRIMARY KEY " if column.primary
            column_sql << " NOT NULL " unless column.null
            column_sql
          }.join(', ') } );"
        end
    
        private
    
        def self.sql_type column
          case column.type
          when 'datetime', 'string'
            'TEXT'
          else
            column.type.to_s
          end
        end
    
      end
    end
    

    Then, if I need to create tables and insert records, taking the same code of the question as example, I must to run:

    def download_link
      temp_file = Tempfile.new 'temp_file'
      temp_sqlite_db = SQLite3::Database.new temp_file.path
    
      temp_sqlite_db.execute(Inspection.sql_create)
      inspections = Inspection.a_heavy_query_that_doesnt_worths_to_wait_so_much_for_a_reply
      insert = ""
      inspections.each{ |insp|
        insert << insp.return_insert_sql
      }
      #.....
    end
    

    For the first method sql_insert I took as example the create method code of ActiveRecord. I know that maybe some kittens died coding this implementation, but at least for me it works.

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

Sidebar

Related Questions

I have a controller code like this : def test23() { //params.id23 is been
So basically I have a controller. something like this def show @user = User.find[:params[id]]
I have a controller for an API that looks like this: def index respond_to
I have a controller like this : def mytask = { def user =
I have controller methods that look like this: class TestController < ApplicationController def testAction
I have a method in my controller which uses send_data like this: def show
In our code we used to have something like this: *(controller->bigstruct) = ( struct
I have an action like this: public class News : System.Web.Mvc.Controller { public ActionResult
If you have a controller method like so: @expose(json) def artists(self, action=view,artist_id=None): artists=session.query(model.Artist).all() return
I have class methods like these in a message model: def delete_all_users_messages(user_id, parent_id) message

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.