Problem running ruby script with rails42

85 views
Skip to first unread message

PandaR1

unread,
Jan 30, 2015, 11:43:43 AM1/30/15
to rubyonra...@googlegroups.com
This very simple script was running in 4.1.6

require '.\config\config.rb'
require '.\models\transazioni.rb'

Transazioni.where(isprocessed: 'N').each do |tr|
puts tr.id_transazione + ' ' + tr.transdate.to_s + ' ' + tr.idmaximo.to_s + ' ' + tr.codsap
end

exit


database.yml:

# DATA SOURCE
datasource:  
  adapter: oracle_enhanced  
  url: jdbc:oracle:thin:@x.x.x.x:1521:xxxx
  username: xxx
  password: xxx



config.rb:

require 'rubygems'
require 'active_record'
require 'yaml'
require 'logger'
require 'C:/jrails4/jruby/lib/ojdbc6.jar'

@config_db = YAML::load(File.open("config/database.yml"))
$src_db = @config_db["datasource"]


Now with 4.2.0 I got this error:

C:/jrails4_update/jruby/lib/ruby/gems/shared/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:587 warning: already initialized constant Reference
C:/jrails4_update/jruby/lib/ruby/gems/shared/gems/activesupport-4.2.0/lib/active_support/values/time_zone.rb:37 warning: already initialized constant MAPPING
C:/jrails4_update/jruby/lib/ruby/gems/shared/gems/activesupport-4.2.0/lib/active_support/values/time_zone.rb:186 warning: already initialized constant UTC_OFFSET_WITH_COLON
C:/jrails4_update/jruby/lib/ruby/gems/shared/gems/activesupport-4.2.0/lib/active_support/values/time_zone.rb:187 warning: already initialized constant UTC_OFFSET_WITHOUT_COLON
C:/jrails4_update/jruby/lib/ruby/gems/shared/gems/activerecord-4.2.0/lib/active_record/relation/delegation.rb:40 warning: already initialized constant BLACKLISTED_ARRAY_METHODS
ActiveSupport::Concern::MultipleIncludedBlocks: Cannot define multiple 'included' blocks for a Concern
               included at C:/jrails4_update/jruby/lib/ruby/gems/shared/gems/activesupport-4.2.0/lib/active_support/concern.rb:126
  ClassSpecificRelation at C:/jrails4_update/jruby/lib/ruby/gems/shared/gems/activerecord-4.2.0/lib/active_record/relation/delegation.rb:54
             Delegation at C:/jrails4_update/jruby/lib/ruby/gems/shared/gems/activerecord-4.2.0/lib/active_record/relation/delegation.rb:51
           ActiveRecord at C:/jrails4_update/jruby/lib/ruby/gems/shared/gems/activerecord-4.2.0/lib/active_record/relation/delegation.rb:6
                 (root) at C:/jrails4_update/jruby/lib/ruby/gems/shared/gems/activerecord-4.2.0/lib/active_record/relation/delegation.rb:5
                require at org/jruby/RubyKernel.java:1071
                require at C:/jrails4_update/jruby/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:69
                require at C:/jrails4_update/jruby/lib/ruby/gems/shared/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274
        load_dependency at C:/jrails4_update/jruby/lib/ruby/gems/shared/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240
                require at C:/jrails4_update/jruby/lib/ruby/gems/shared/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274
                 (root) at C:/jrails4_update/jruby/lib/ruby/gems/shared/gems/activerecord-4.2.0/lib/active_record/base.rb:1
                 (root) at C:/jrails4_update/jruby/lib/ruby/gems/shared/gems/activerecord-4.2.0/lib/active_record/base.rb:23
                require at org/jruby/RubyKernel.java:1071
                require at C:/jrails4_update/jruby/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:121
                 (root) at transcont.rb:4

Do I have to modify something or it's a bug?

Tnx
Fabio

PandaR1

unread,
Jan 30, 2015, 11:45:57 AM1/30/15
to rubyonra...@googlegroups.com
P.S.

transazioni.rb (model)

class Transazioni < ActiveRecord::Base   
  self.table_name = 'TRANSAZIONI_CONTABILI'
  establish_connection($src_db)
end

Colin Law

unread,
Jan 30, 2015, 11:57:01 AM1/30/15
to rubyonra...@googlegroups.com
My guess would be that something is getting loaded twice. I suggest
taking out all the requires and putting them back till you get the
problem. That may help you to home in on it.

Colin

PandaR1

unread,
Feb 2, 2015, 5:17:57 AM2/2/15
to rubyonra...@googlegroups.com
My guess would be that something is getting loaded twice.  I suggest
taking out all the requires and putting them back till you get the
problem.  That may help you to home in on it.

Yes, it seems some constant is already initialized.

I tried removing the includes, but they are all needed... 

Colin Law

unread,
Feb 2, 2015, 6:41:42 AM2/2/15
to rubyonra...@googlegroups.com
The point is which is the one you add that causes this particular
error to occur? Once you find that then leave it in and take the
others out, then add them back in one at a time to find out which is
the one that adds the second initialisation.

Colin

Xavier Noria

unread,
Feb 2, 2015, 8:14:02 AM2/2/15
to rubyonrails-talk
The natural way to run a script in a Rails environment is to use the runner command.

1) Remove manual requires.

2) bin/rails runner my_script.rb


PandaR1

unread,
Feb 2, 2015, 12:57:15 PM2/2/15
to rubyonra...@googlegroups.com
The point is which is the one you add that causes this particular
error to occur?  Once you find that then leave it in and take the
others out, then add them back in one at a time to find out which is
the one that adds the second initialisation.

I can remove require 'rubygems'

But if I remove the next require line which requires activerecord then I got a name error which says that active record is not defined

Same thing if I remove require yaml... and if I require active record and yaml then the error arise, even if I don't require logger...

PandaR1

unread,
Feb 2, 2015, 12:58:55 PM2/2/15
to rubyonra...@googlegroups.com
does not seems to work under jruby... rails  batch seems to not support the runner option... 

Hassan Schroeder

unread,
Feb 2, 2015, 1:39:31 PM2/2/15
to rubyonrails-talk
On Fri, Jan 30, 2015 at 8:43 AM, PandaR1 <fabio.mo...@gmail.com> wrote:

> Now with 4.2.0 I got this error:

> Do I have to modify something or it's a bug?

See: https://github.com/jruby/jruby/issues/2286

I suspect that's your issue.

HTH!
--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
http://about.me/hassanschroeder
twitter: @hassan
Consulting Availability : Silicon Valley or remote
Message has been deleted

d

unread,
Apr 10, 2015, 8:53:10 AM4/10/15
to rubyonra...@googlegroups.com
Did you find out how to fix this?

PandaR1

unread,
Sep 14, 2015, 11:22:42 AM9/14/15
to Ruby on Rails: Talk


Il giorno venerdì 10 aprile 2015 14:53:10 UTC+2, d ha scritto:
Did you find out how to fix this?

Yes, it was a jruby problem, I solved with jruby 1.7.22

;) 
Reply all
Reply to author
Forward
0 new messages