odd number list for Hash (SyntaxError), though I am using Ruby 1.8.7 hash declaration - ruby

I am trying to connect to Oracle database using 'activerecord' and Ruby 1.8.7 and getting below error on my Windows 7 machine. I searched around for this issue and came across 1.8 and 1.9 ruby declaration of 'Hash' however I am using Ruby 1.8.7 and I feel I am using correct hash declaration, please correct me if I am wrong.
C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:29:in `gem_original_require': C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-oracle_enhancedadapter-1.5.3/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:917: odd number list for Hash (SyntaxError)
read_committed: "READ COMMITTED",
^
C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-adapter-1.5.3/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:917: syntax error, unexpected ':', expecting '}'
read_committed: "READ COMMITTED",
^
C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-adapter-1.5.3/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:917: syntax error, unexpected ',', expecting kEND
C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-adapter-1.5.3/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:919: syntax error, unexpected '}', expecting kEND
C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-adapter-1.5.3/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:1471: dynamic constant assignment
DBMS_OUTPUT_BUFFER_SIZE = 10000 # can be 1-1000000
^
C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-adapter-1.5.3/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:1555: syntax error, unexpected $end, expecting kEND
from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:29:in `require'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:156:in `require'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:521:in `new_constants_in'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:156:in `require'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/connection_specification.rb:71:in `establish_connection'
from oracle_conn_testing.rb:5
This is how my code looks like
require 'rubygems'
gem "activerecord-oracle_enhanced-adapter"
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => "oracle_enhanced",
:database => "someurl.net:1523/ABCAD",
:username => "testing1",
:password => "testing1")
class TestTable < ActiveRecord::Base
set_table_name "TABLE_NAME"
set_primary_key "ID"
end
TestTable.find(:all).each do |tt|
p tt
end
nac = TestTable.new()
Additional Information:
I have below gems on my machine :
* LOCAL GEMS *
actionmailer (2.3.4)
actionpack (2.3.4)
activerecord (2.3.4)
activerecord-oracle_enhanced-adapter (1.5.3)
activeresource (2.3.4)
activesupport (2.3.4)
json (1.8.1)
mysql (2.9.1 x86-mingw32)
rack (1.0.1)
rails (2.3.4)
rake (10.1.1)
ruby-oci8 (2.1.7 x86-mingw32)
rubygems-update (1.4.2)
I use below Rubygems version:
C:\Users\tester1>gem -v
1.4.2
I tried to connect using OCI8 and I was able to get response out of Oracle database so there is no connectivity issue from my machine.
irb(main):006:0> OCI8.new('testing1', 'testing1', 'someurl.net:1523/ABCAD').exec('select sysdate from dual') do |r| puts r.join(', ') end
Mon Mar 10 15:09:23 -0400 2014
=> 1
I used below link as my reference:
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/oow10/rubyhol/instructions/rubyrails.htm

The error message shows that your error is coming from inside the activerecord-oracle_enhancedadapter gem, and that gem has a Ruby 1.9 style hash. You might find an older version of that gem that supports Ruby 1.8 and switch to that version.

Related

uninitialized constant ActiveRecord::ConnectionAdapters::ConnectionManagement

Im currently working on a sinatra app, and im having a trouble regarding postgresql connection to sinatra, im try to execute this command:
rake db:create
to create the database but it throws this error.
C:\Users\John\Documents\Registration_Sinatra>rake db:create
rake aborted!
NameError: uninitialized constant ActiveRecord::ConnectionAdapters::ConnectionManagement
C:/Users/John/Documents/Registration_Sinatra/app/app.rb:2:in `<top (required)>'
C:/Users/John/Documents/Registration_Sinatra/Rakefile:1:in `<top (required)>'
LoadError: cannot load such file -- sinatra/activerecord
C:/Users/John/Documents/Registration_Sinatra/app/app.rb:2:in `<top (required)>'
C:/Users/John/Documents/Registration_Sinatra/Rakefile:1:in `<top (required)>'
(See full trace by running task with --trace)
this is my app.rb
require 'sinatra'
require 'sinatra/activerecord'
require 'pg'
require './config/environments'
class RegistrationSinatra < ActiveRecord::Base
end
get '/' do
erb :index
end
this is my environments.rb
configure :development do
#DEFAULT_CONN = {database: 'development_registration_sinatra', user: 'postgres', password: 'secret123', host: 'localhost'}
db = URI.parse(ENV['DATABASE_URL'] || "postgres://#{#DEFAULT_CONN[:host]}/#{#DEFAULT_CONN[:database]}?user=#{#DEFAULT_CONN[:user]}")
ActiveRecord::Base.establish_connection(
:adapter => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
:host => #DEFAULT_CONN[:host],
:username => #DEFAULT_CONN[:user],
:password => #DEFAULT_CONN[:password],
:database => db.path[1..-1],
:encoding => 'utf8')
end
this is my gemfile
source 'https://rubygems.org'
ruby "2.2.2"
gem 'sinatra'
gem 'activerecord'
gem 'sinatra-activerecord'
gem 'tux'
gem 'pg'
and my Rakefile
require './app/app'
require 'sinatra/activerecord/rake'
hope you guys can pin point what's wrong with my sample app so i can progress thanks.
Here is the solution: https://github.com/janko-m/sinatra-activerecord/pull/66
In your Gemfile, add:
gem "activerecord", "< 5.0.0"
run bundle update and it will work.

Unable to send exception data to Raygun through the rails app and rake test task. Works through Rails Console

I am unable to send exception data to Raygun through the Rails App and the Rake Test task on our staging environment. The sending of exception data works through the Rails Console though.
Raygun.rb
Raygun.setup do |config|
config.api_key = [Key]
config.filterparameters = Rails.application.config.filterparameters
config.enable_reporting = !Rails.env.development?
end
Gemfile.lock raygun entry
raygun4ruby (1.1.9)
httparty (~> 0.11)
json
rack
The error that I get when I try the rake test
$ RAILS_ENV=production rake raygun:test
Oh-oh, something went wrong - double check your API key
API Key - [FIltered])
rake aborted!
TypeError: no implicit conversion of HTTParty::Response into String
/var/lib/gems/2.3.0/gems/raygun4ruby-1.1.9/lib/raygun/testable.rb:17:in `rescue in tracktestexception'
/var/lib/gems/2.3.0/gems/raygun4ruby-1.1.9/lib/raygun/testable.rb:8:in `tracktestexception'
/var/lib/gems/2.3.0/gems/raygun4ruby-1.1.9/lib/tasks/raygun.tasks:5:in `block (2 levels) in
Raygun::ItWorksException: Woohoo! Your Raygun<->Ruby connection is set up correctly
/var/lib/gems/2.3.0/gems/raygun4ruby-1.1.9/lib/raygun/testable.rb:9:in `tracktestexception'
/var/lib/gems/2.3.0/gems/raygun4ruby-1.1.9/lib/tasks/raygun.tasks:5:in `block (2 levels) in
Tasks: TOP => raygun:test
(See full trace by running task with --trace)
We are using AWS for our staging environment. It is surprising to me that Rails C works while through the app and rake test it does not.
When done through the Rails Console
irb(main):003:0> class ItWorksException < StandardError; end
=> nil
irb(main):004:0> e = ItWorksException.new("Woohoo! Your Raygun<->Ruby connection is set up correctly")
=> #
irb(main):005:0> response = Raygun.track_exception(e)
[Raygun] Tracking Exception...
=> #
irb(main):006:0> response.success?
=> true
This may seem a bit odd, but can you try running it in a slightly different order like:
rake RAILS_ENV=production raygun:test

Using gems in Ruby *basic*

I'm a complete newbie.
I have a gem I want to install and use, let's say it's this one:
https://rubygems.org/gems/linkedindata/versions/0.0.22
I'm using cmd:
gem install linkedindata
#1 gem installed
After that I add it to my gemfile:
gemrat 'linkedindata'
#gem 'linkedindata', '0.0.22' added to your Gemfile.
Now to use linkedindata I have to create a new object and specify my search. So I do:
**test.rb**
l = LinkedinData.new(1, "c:/users/proxylist.txt", true, true)
searchTerms = ['First', 'Second', 'Third']
l.getByKeywords(searchTerms)
Now I run the test.rb from command prompt:
test.rb:1:in `<main>': undefined local variable or meth
od `linkedindata' for main:Object (NameError)
So, I obviously need to require the 'linkedindata' gem here. I added:
**test.rb**
require 'LinkedinData'
l = LinkedinData.new(1, "c:/users/proxylist.txt", true, true)
searchTerms = ['First', 'Second', 'Third']
l.getByKeywords(searchTerms)
I get the following error:
C:/Ruby22/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `re
quire': cannot load such file -- linkedin-scraper (LoadError)
from C:/Ruby22/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require
.rb:54:in `require'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/linkedindata-0.0.22/lib/linkedin
data.rb:1:in `<top (required)>'
from C:/Ruby22/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require
.rb:128:in `require'
from C:/Ruby22/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require
.rb:128:in `rescue in require'
from C:/Ruby22/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require
.rb:39:in `require'
from C:/Users/test.rb:1:in `<main>'
Am I doing something fundamentally wrong here? Or is there a problem with this gem?
UPDATE
The problem was within the gem, see Doon's answer below.
require 'rubygems'
require 'bundler/setup'
require 'linkedindata'
l = LinkedinData.new(1, "proxylist.txt", true, true)
searchTerms = ['First', 'Second', 'Third']
l.getByKeywords(searchTerms)
++++ correct how the gem requires "linkedin_scraper" in linkedindata.rb
Next problem occurs
C:/Ruby22/lib/ruby/gems/2.2.0/gems/linkedindata-0.0.22/lib/linkedin.rb:6:in `<cl
ass:Profile>': uninitialized constant Linkedin::Profile::ProxyManager (NameError
)
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/linkedindata-0.0.22/lib/linkedin
.rb:5:in `<module:Linkedin>'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/linkedindata-0.0.22/lib/linkedin
.rb:4:in `<top (required)>'
from linkedinscrape.rb:4:in `require'
from linkedinscrape.rb:4:in `<main>'
Which obviously has to do with the proxy settings. The list:
**proxylist.txt**
220.248.224.242:8089
165.139.179.225:8080
54.207.114.172:3333
190.63.174.246:8081
The way I load it:
l = LinkedinData.new(1, "c:/users/proxylist.txt")
As you are using a Gemfile, you are using bundler. In your script you will need to include rubygems and bundler to make it work. Try this
require 'rubygems'
require 'bundler/setup'
require 'linkedindata'
l = LinkedinData.new(1, "c:/users/proxylist.txt", true, true)
searchTerms = ['First', 'Second', 'Third']
l.getByKeywords(searchTerms)
You have run bundle install, sorry not familiar with gemrat, so not sure how much it does for you.
if you are not actually using bundler, just remove require 'bundler/setup' from the code above, you will still need to require rubygems though in your script.
in looks like the gem itself is kind of broken in the way it declare dependencies, and the other gems that it relies on. I appear to be able to make it work as follows:
Gemfile:
source 'https://rubygems.org'
gem 'linkedin-scraper'
gem 'linkedindata'
gem 'generalscraper'
gem 'uploadconvert'
gem 'docsplit'
gem 'crack'
gem 'pry'
gem 'activesupport'
gem 'selenium-webdriver'
It also appears that it the linkedin-scraper needs to required as linkedin_scraper but not sure why that is. So editing.
{GEMPATH}/linkedindata-0.0.22/lib/linkedindata.rb to require 'linkedin_scraper' as opposed to require 'linkedin-scraper' seems to make it work.
So with the above changes and using bundler
require 'rubygems'
require 'bundler/setup'
require 'linkedindata'
l = LinkedinData.new(1, "proxylist.txt", true, true)
searchTerms = ['First', 'Second', 'Third']
l.getByKeywords(searchTerms)
now runs (I don't have a proxylist.txt so it blows up looking for it, but it doesn't get anymore library errors).

unable to overcome the error PAC::ProgramError from my Rails application

I am new to Ruby. I have written a simple code :
...
pac = PAC.load(pacfilename)
return pac.find('http://www.google.com')
...
I am using gems
gem 'win32-service', '0.8.2', :platforms => :mingw
gem 'pac', "~> 1.0.0"
gem 'therubyracer', '0.11.0beta1', :platforms => :mingw
I am getting this following error :
PAC::ProgramError in Accounts#new
Showing G:/test/app/views/accounts/new.html.erb where line #6 raised:
Cannot call method 'lastIndexOf' of null
Extracted source (around line #6):
3: >
4:
5:
6: <%= getProxyServer %>
7:
8: <%= link_to 'Back', accounts_path %>
The relevant part of trace file
pac (1.0.0) lib/pac/runtimes/rubyracer.rb:28:in rescue in block in call'
pac (1.0.0) lib/pac/runtimes/rubyracer.rb:22:inblock in call'
pac (1.0.0) lib/pac/runtimes/rubyracer.rb:57:in block in lock'
pac (1.0.0) lib/pac/runtimes/rubyracer.rb:55:incall'
pac (1.0.0) lib/pac/runtimes/rubyracer.rb:55:in Locker'
pac (1.0.0) lib/pac/runtimes/rubyracer.rb:55:inlock'
pac (1.0.0) lib/pac/runtimes/rubyracer.rb:21:in call'
pac (1.0.0) lib/pac/file.rb:18:infind'
app/helpers/accounts_helper.rb:46:in readPACfileData'
app/helpers/accounts_helper.rb:65:inreadPACfile'
app/helpers/accounts_helper.rb:83:in `getProxyServer'
What is the problem? I want to find out the proxyserverIP, if any, programmatically from the application and then use it for accessing websites. Any help?

Issues with mysql2 with and ruby

Trying to get the gem mysql2 installed on ubuntu and I have tried all of the suggestions but I cannot get it to run. Here is the error in my application.
./bla.rb:65:in `post_init': undefined method `query' for nil:NilClass (NoMethodError)
from /var/lib/gems/1.8/gems/eventmachine-0.12.10/lib/em/timers.rb:51:in `call'
from /var/lib/gems/1.8/gems/eventmachine-0.12.10/lib/em/timers.rb:51:in `fire'
from /var/lib/gems/1.8/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `call'
from /var/lib/gems/1.8/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
from /var/lib/gems/1.8/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
from ./bla.rb:234:in `start_server'
from ./bin/minibardaemon:15
from /var/lib/gems/1.8/gems/daemons-1.1.8/lib/daemons/application.rb:254:in `call'
from /var/lib/gems/1.8/gems/daemons-1.1.8/lib/daemons/application.rb:254:in `start_proc'
from /var/lib/gems/1.8/gems/daemons-1.1.8/lib/daemons/application.rb:263:in `call'
from /var/lib/gems/1.8/gems/daemons-1.1.8/lib/daemons/application.rb:263:in `start_proc'
from /var/lib/gems/1.8/gems/daemons-1.1.8/lib/daemons/application.rb:295:in `start'
from /var/lib/gems/1.8/gems/daemons-1.1.8/lib/daemons/controller.rb:73:in `run'
from /var/lib/gems/1.8/gems/daemons-1.1.8/lib/daemons.rb:197:in `run_proc'
from /var/lib/gems/1.8/gems/daemons-1.1.8/lib/daemons/cmdline.rb:109:in `call'
from /var/lib/gems/1.8/gems/daemons-1.1.8/lib/daemons/cmdline.rb:109:in `catch_exceptions'
from /var/lib/gems/1.8/gems/daemons-1.1.8/lib/daemons.rb:196:in `run_proc'
I have installed all of the packages that are recommended and installed mysql2 via gem but still no luck.
libmysqlclient-dev
Is installed.
Im on Ubuntu.
# gem -v
1.3.7
# ruby -v
ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]
Installing the gems
# gem install mysql
Building native extensions. This could take a while...
Successfully installed mysql-2.8.1
1 gem installed
Installing ri documentation for mysql-2.8.1...
Installing RDoc documentation for mysql-2.8.1...
# gem install mysql2
Building native extensions. This could take a while...
Successfully installed mysql2-0.3.11
1 gem installed
Installing ri documentation for mysql2-0.3.11...
Installing RDoc documentation for mysql2-0.3.11...
def create_mysql2
begin
mysql2 = Mysql2::EM::Client.new(
:username => DBUSER,
:password => DBPASS,
:host => DBHOST,
:port => DBPORT,
:socket => DBSOCKET,
:database => DBNAME
)
return mysql2
rescue Mysql2::Error => exception
$stderr.puts "Mysql Error: #{ exception.message }"
EventMachine::stop_event_loop
end
end
...
begin
mysql2 = create_mysql2
rescue Exception => ex
p ex
end
# query the db every x seconds.
EventMachine::add_periodic_timer(QUERY_INTERVAL) do
defer1 = mysql2.query "SELECT * FROM table LIMIT #{QUERY_LIMIT}"
doesn't realy look like mysql2 gem issue, could you please show 65'th line of you bla.rb file? And probably some number of lines that surround it.
it actually looks like your mysql2 client gets uninitialized for some reason.
I would advice to check if something like this works:
require 'mysql2'
mysql_client = Mysql2::Client.new(:host => "localhost", :username => "root")
mysql_client.query('sql .. ')
if so, there's clearly an issue in your script

Resources