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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:14:22+00:00 2026-06-04T17:14:22+00:00

I need to push some data from and old application using access to the

  • 0

I need to push some data from and old application using access to the new one that I created with Rails. I’ve exported Access data to .xls accessing it with the gem roo.

It works pretty fine, I created a script and by printing results I’m sure it does all properly, now I’d like to have it to insert automatically this data inside the database, accessing the rails application models.

I tried putting the file under my rails’ lib/ directory and then I required it within the environments/development.rb, but when I import the ruby file it claims that cannot find some variables I need to do the processing.

For completeness this is the whole source code I developed to extract data from the xls and edit it to match the new db schema.

# encoding: utf-8

require 'rubygems'
require 'roo'

user_id_conversion = {119 => 10, 152 => 11, 145 => 12, 161 => 13, 163 => 14, 158 => 15}
conversion_hours = {15 => 14, 17 => 16, 19 => 18}
hostess_id_conversion = {139 => 9, 157 => 17, 153 => 18, 110 => 20, 40 => 19, 141 => 21, 121 => 22, 151 => 23}
status_conversion = {1 => "Inserito", 2 => "Rifiutato", 3 => "Visitato", 4 => "Inserito", 5 => "Ricontattare", 6 => "Vendita"}
mall_id_conversion = {51 => 1, 56 => 2, 53 => 3, 54 => 4, 59 => 5, 65 => 6}

xls = Excel.new("/home/lex/Scrivania/appointments.xls")
xls.default_sheet = xls.sheets.first

city_list = []

# change this to current row numbers
1.upto(3829) do |line|
  uid        = xls.cell(line,'B').to_i

  if user_id_conversion.has_key? uid
    id         = xls.cell(line, 'A')
    uid        = user_id_conversion[uid]
    name       = xls.cell(line, 'F')
    surname    = xls.cell(line, 'E')
    city       = xls.cell(line, 'O')
    street     = xls.cell(line, 'G')
    start_at   = xls.cell(line, 'C')
    start_time = xls.cell(line, 'D')/60/60
    street_no  = xls.cell(line, 'M')
    telephone  = xls.cell(line, 'H')
    mobile     = xls.cell(line, 'I')
    email      = xls.cell(line, 'J')
    notes      = xls.cell(line, 'L')
    agent_note = xls.cell(line, 'U')
    status     = xls.cell(line, 'S')
    signed_by  = xls.cell(line, 'P')
    mall       = xls.cell(line, 'T')

    # we only want to move May -> future
    if start_at.month >= Date.today.month
      ##
      # COMPATIBILITY MODE
      ##
      if conversion_hours.has_key? start_time
        compatibility = true
      else
        compatibility = false
      end

      ##
      # WHO SIGNED THAT APPOINTMENT?
      ##
      if hostess_id_conversion.has_key? signed_by
        signed_by = hostess_id_conversion[signed_by]
      elsif user_id_conversion.has_key? signed_by
        signed_by = user_id_conversion[signed_by]
      else
        signed_by = -1 # display "user deleted"
      end

      ##
      # APPOINTMENT OR EXCLUDED FIELD?
      ##
      available = true
      if status == 4
        available = false
      end
      status = status_conversion[status]

      ##
      # todo SELECT CITY ID FROM DATABASE
      ##
      # city = Municipality.find_by_name(city)
      #

      ##
      # CONVERT MALL_ID
      ##
      if mall_id_conversion.has_key? mall
        mall = mall_id_conversion[mall]
      else
        mall = nil
      end

      ##
      # EMAIL is REQUIRED
      ##
      no_email = false
      if email.blank?
        no_email = true
      end

      ##
      # CONVERT APPOINTMENT DATES TO NEW ONES
      ##
      if compatibility
        old_start_at = DateTime.new start_at.year, start_at.month, start_at.day, start_time
        start_at     = DateTime.new start_at.year, start_at.month, start_at.day, conversion_hours[start_time]
      else
        old_start_at = nil
        start_at     = DateTime.new start_at.year, start_at.month, start_at.day, start_time
      end

      ##
      # todo interesting products
      #    serramenti: boolean, tende_sole: boolean, tecnic: boolean,
      #    tende_veranda: boolean, porte_interne: boolean, tapparelle: boolean, blindati: boolean,
      #    zanzariere: boolean,
      ##

      ##
      # todo INSERT THIS APPOINTMENT
      ##
=begin
      if available == false
        Event.new(
          :event_calendar_id => User.find(uid).event_calendar,
          :status => "Inserito",
          :available => false
          )
      else
        Event.new(
          :event_calendar_id => User.find(uid).event_calendar,
          :signed_by_id => User.find_by_id(signed_by),
          :mall_id => Mall.find_by_id(mall),
          :status => status,
          :name => name,
          :surname => surname,
          :street => street,
          :street_no => street_no,
          :city_id => city.name,
          :telephone => telephone,
          :mobile => mobile,
          :email => email,
          :no_email => no_email,
          :inserting_notes => notes,
          :seller_notes => agent_note,
          :start_at => start_at,
          :available => true,
          group_id: 3,
          :compatibility_start_at => old_start_at
          )
      end
=end

    end
  end
end

How can I make this work inside the rails environment?
I was thinking to make something like a class or a function to be run inside the rails c console because I’ll need to run this this evening to get the most updated database version, extract the xls with updated records and do the magic.

Sorry if this may seem a noob question but I’m new to Ruby.

P.S. I’m using Rails 3.2.3 w/Ruby 1.9.3
P.P.S. I inserted ‘roo’ inside the Gemfile since it was first not finding the gem.

Thanks.

  • 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-04T17:14:23+00:00Added an answer on June 4, 2026 at 5:14 pm

    If you do

    rails runner path/to/script
    

    Then rails will load the rails environment and then run your script

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

Sidebar

Related Questions

I'm writing web application where I need to push data from server to the
I need to push some data from server to client in arbitrary manner, i
I am using BlazeDS for data-push feature in my Flex application project. From the
I need to clone some data from a master source in the ViewModel into
I am trying to display some xml data from remote URL using jquery and
I have a requirement where I need to send some data from my server
I have a Rails web app that is used to gather data from an
I need to push some JSON data to my website which I would like
In my application I need to push notifications of real time events from server
I'm evaluating several Comet servers because I need HTTP Push in a new project

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.