Getting NoMethodError when using jdbc sqlserver adapter with jRuby on Rails - sql-server

I have a jRuby on Rails application hosted on IIS 8 on Windows Server 2012 R2 (I know, I must be insane). After about 2 weeks of painful programming I have a working application but I'm trying to configure it to use SQL Server 2012 Express via the Microsoft JDBC SQL Server driver instead of the default sqlite3 database. So far, this is not going well.
After configuring my database.yml file I tried to run: bundle exec rake db:migrate RAILS_ENV=production --traceI am met with the error rake aborted! NoMethodError: undefined method 'type' for "nvarchar(255)":StringA full trace of my error can be seen below:
rake db:migrate
C:\inetpub\wwwroot\rails>bundle exec rake db:migrate RAILS_ENV=production --trac
e
io/console not supported; tty will not be manipulated
io/console not supported; tty will not be manipulated
NOTE: ActiveRecord 4.2 is not (yet) fully supported by AR-JDBC, please help us f
inish 4.2 support - check http://bit.ly/jruby-42 for starters
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
rake aborted!
NoMethodError: undefined method `type' for "nvarchar(255)":String
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/activerecord-4.2.2/lib/active_record/a
ttribute_methods/time_zone_conversion.rb:64:in `create_time_zone_conversion_attr
ibute?'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/activerecord-4.2.2/lib/active_record/a
ttribute_methods/time_zone_conversion.rb:53:in `inherited'
org/jruby/RubyProc.java:271:in `call'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/activerecord-4.2.2/lib/active_record/a
ttribute_decorators.rb:61:in `matching'
org/jruby/RubyArray.java:2470:in `select'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/activerecord-4.2.2/lib/active_record/a
ttribute_decorators.rb:60:in `matching'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/activerecord-4.2.2/lib/active_record/a
ttribute_decorators.rb:56:in `decorators_for'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/activerecord-4.2.2/lib/active_record/a
ttribute_decorators.rb:47:in `apply'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/activerecord-4.2.2/lib/active_record/a
ttribute_decorators.rb:29:in `add_user_provided_columns'
org/jruby/RubyArray.java:2414:in `map'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/activerecord-4.2.2/lib/active_record/a
ttribute_decorators.rb:28:in `add_user_provided_columns'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/activerecord-4.2.2/lib/active_record/a
ttributes.rb:93:in `columns'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/activerecord-4.2.2/lib/active_record/a
ttributes.rb:98:in `columns_hash'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/activerecord-4.2.2/lib/active_record/q
uerying.rb:41:in `find_by_sql'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/activerecord-4.2.2/lib/active_record/r
elation.rb:638:in `exec_queries'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/activerecord-4.2.2/lib/active_record/r
elation.rb:514:in `load'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/activerecord-4.2.2/lib/active_record/r
elation.rb:243:in `to_a'
C:0:in `map'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/activerecord-4.2.2/lib/active_record/m
igration.rb:844:in `get_all_versions'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/activerecord-4.2.2/lib/active_record/m
igration.rb:985:in `migrated'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/activerecord-4.2.2/lib/active_record/m
igration.rb:990:in `ran?'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/activerecord-4.2.2/lib/active_record/m
igration.rb:967:in `runnable'
org/jruby/RubyArray.java:2640:in `reject!'
org/jruby/RubyArray.java:2611:in `reject'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/activerecord-4.2.2/lib/active_record/m
igration.rb:967:in `runnable'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/activerecord-4.2.2/lib/active_record/m
igration.rb:952:in `migrate'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/activerecord-4.2.2/lib/active_record/m
igration.rb:820:in `up'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/activerecord-4.2.2/lib/active_record/m
igration.rb:798:in `migrate'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/activerecord-4.2.2/lib/active_record/t
asks/database_tasks.rb:137:in `migrate'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/activerecord-4.2.2/lib/active_record/r
ailties/databases.rake:44:in `(root)'
org/jruby/RubyProc.java:271:in `call'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/rake-10.4.2/lib/rake/task.rb:240:in `e
xecute'
org/jruby/RubyArray.java:1613:in `each'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/rake-10.4.2/lib/rake/task.rb:235:in `e
xecute'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/rake-10.4.2/lib/rake/task.rb:179:in `i
nvoke_with_call_chain'
C:/jruby-1.7.22/lib/ruby/1.9/monitor.rb:211:in `mon_synchronize'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/rake-10.4.2/lib/rake/task.rb:172:in `i
nvoke_with_call_chain'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/rake-10.4.2/lib/rake/task.rb:165:in `i
nvoke'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/rake-10.4.2/lib/rake/application.rb:15
0:in `invoke_task'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/rake-10.4.2/lib/rake/application.rb:10
6:in `top_level'
org/jruby/RubyArray.java:1613:in `each'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/rake-10.4.2/lib/rake/application.rb:10
6:in `top_level'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/rake-10.4.2/lib/rake/application.rb:11
5:in `run_with_threads'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/rake-10.4.2/lib/rake/application.rb:10
0:in `top_level'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/rake-10.4.2/lib/rake/application.rb:78
:in `run'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/rake-10.4.2/lib/rake/application.rb:17
6:in `standard_exception_handling'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/rake-10.4.2/lib/rake/application.rb:75
:in `run'
C:/jruby-1.7.22/lib/ruby/gems/shared/gems/rake-10.4.2/bin/rake:33:in `(root)'
org/jruby/RubyKernel.java:1059:in `load'
C:\jruby-1.7.22\bin\rake:23:in `(root)'
Tasks: TOP => db:migrate
database.yml
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
production:
adapter: sqlserver
database: smdb
url: jdbc:sqlserver://localhost;instanceName=SQLEXPRESS;databaseName=smdb;user=sa;password=password123;
Gemfile
source 'https://rubygems.org'
ruby '1.9.3', :engine => 'jruby', :engine_version => '1.7.22'
gem 'rails', '4.2.2'
gem 'bootstrap-sass', '3.2.0.0'
gem 'sass-rails', '5.0.2'
gem 'uglifier', '2.5.3'
gem 'coffee-rails', '4.1.0'
gem 'coffee-script-source', '1.8.0'
gem 'jquery-rails', '4.0.3'
gem 'turbolinks', '2.3.0'
gem 'jbuilder', '2.2.3'
gem 'faker', '1.4.2'
gem 'tzinfo-data', '1.2015.6'
gem 'sdoc', '0.4.0', group: :doc
group :development, :test do
gem 'activerecord-jdbcsqlite3-adapter', '1.3.17'
gem 'spring', '1.1.3'
end
group :test do
gem 'minitest-reporters', '1.0.5'
gem 'mini_backtrace', '0.1.3'
gem 'guard-minitest', '2.3.1'
end
group :production do
gem 'trinidad', '1.4.6'
gem 'deprecated', '3.0.1'
gem 'activerecord-jdbcmssql-adapter', '1.3.17'
end
And finally my two Database Migration files:
20150805101650_create_servers.rb
class CreateServers < ActiveRecord::Migration
def change
create_table :servers do |t|
t.string :server_name
t.string :application
t.string :server_role
t.string :team_contact
t.string :individual_contact
t.string :business_owner
t.string :vendor
t.string :vendor_contact
t.string :main_doc
t.string :main_win
t.timestamps null: false
end
end
end
20150805105953_add_index_to_server_name.rb
class AddIndexToServerName < ActiveRecord::Migration
def change
add_index :servers, :server_name, unique: true
end
end
I know that the instance is being hit as I was previously met with an authentication error which has gone since I added the username and password to the jdbc connection string
Solution
Downgraded to Rails 4.1.0 which seems to be more compatible with JDBC Adapter. Ran a rake db:migrate RAILS_ENV=production which resulted in another error. The error was resolved by removing config.active_record.raised_in_transactional_callbacks = true from application.rb

AR-JDBC does not handle Rails 4.2 esp. with databases such as MS-SQL, there's the warning :
NOTE: ActiveRecord 4.2 is not (yet) fully supported by AR-JDBC, please help us finish 4.2 support - check http://bit.ly/jruby-42 for starters
... SQLServer support needs your help/support!

Related

Getting an error Timeout::Error: Timeout::Error with Firefox using Watir-webdriver

I want to run my scripts using firefox 17 but then it launches correctly but fails to navigate completely.
It results in a Timeout::Error: Timeout::Error.
I do NOT see this error with chrome or IE.
Using JRuby 1.7.12, Watir-Webdriver 0.6.10 selenium-webdriver 2.42.0
require 'watir-webdriver'
b = Watir::Browser.new 'firefox'
b.goto 'bit.ly/watir-webdriver-demo'
b.text_field(:id => 'entry_0').set 'your name'
Error message
Timeout::Error: Timeout::Error
from C:/jruby-1.7.12/lib/ruby/1.9/net/protocol.rb:146:in `rbuf_fill'
from C:/jruby-1.7.12/lib/ruby/1.9/net/protocol.rb:122:in `readuntil'
from C:/jruby-1.7.12/lib/ruby/1.9/net/protocol.rb:132:in `readline'
from C:/jruby-1.7.12/lib/ruby/1.9/net/http.rb:2570:in `read_status_line'
from C:/jruby-1.7.12/lib/ruby/1.9/net/http.rb:2559:in `read_new'
from C:/jruby-1.7.12/lib/ruby/1.9/net/http.rb:1327:in `transport_request'
from org/jruby/RubyKernel.java:1264:in `catch'
from C:/jruby-1.7.12/lib/ruby/1.9/net/http.rb:1324:in `transport_request'
from C:/jruby-1.7.12/lib/ruby/1.9/net/http.rb:1301:in `request'
from C:/jruby-1.7.12/lib/ruby/1.9/net/http.rb:1294:in `request'
from C:/jruby-1.7.12/lib/ruby/1.9/net/http.rb:745:in `start'
from C:/jruby-1.7.12/lib/ruby/1.9/net/http.rb:1292:in `request'
from C:/jruby-1.7.12/lib/ruby/gems/shared/gems/selenium-webdriver-2.42.0/lib/selenium/webdriver/remote/http/default.rb:83:in `response_for'
from C:/jruby-1.7.12/lib/ruby/gems/shared/gems/selenium-webdriver-2.42.0/lib/selenium/webdriver/remote/http/default.rb:39:in `request'
from C:/jruby-1.7.12/lib/ruby/gems/shared/gems/selenium-webdriver-2.42.0/lib/selenium/webdriver/remote/http/common.rb:40:in `call'
from C:/jruby-1.7.12/lib/ruby/gems/shared/gems/selenium-webdriver-2.42.0/lib/selenium/webdriver/remote/bridge.rb:634:in `raw_execute'
from C:/jruby-1.7.12/lib/ruby/gems/shared/gems/selenium-webdriver-2.42.0/lib/selenium/webdriver/remote/bridge.rb:612:in `execute'
from C:/jruby-1.7.12/lib/ruby/gems/shared/gems/selenium-webdriver-2.42.0/lib/selenium/webdriver/remote/bridge.rb:110:in `get'
from C:/jruby-1.7.12/lib/ruby/gems/shared/gems/selenium-webdriver-2.42.0/lib/selenium/webdriver/common/navigation.rb:14:in `to'
from C:/jruby-1.7.12/lib/ruby/gems/shared/gems/watir-webdriver-0.6.10/lib/watir-webdriver/browser.rb:77:in `goto'
from (irb):3:in `evaluate'
from org/jruby/RubyKernel.java:1101:in `eval'
from org/jruby/RubyKernel.java:1501:in `loop'
from org/jruby/RubyKernel.java:1264:in `catch'
from org/jruby/RubyKernel.java:1264:in `catch'
from C:\jruby-1.7.12\/bin/jirb_swing:53:in `(root)
in my case this helped:
TIMEOUT = 300 # set some value in seconds, f.ex. 300
client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = TIMEOUT # seconds – default is 60
browser = Watir::Browser.new :firefox, :http_client => client
I have found also:
require 'net/http'
http = Net::HTTP.new(#host, #port)
http.read_timeout = 500
Please, check whether it helps in your case too.
Update your gems, specifically gem update selenium-webdriver

Etherpad - PostgreSQL error: language "plpgsql" does not exist

I installed Etherpad lite and tried to use it with PostgreSQL database, but got this error:
events.js:72
throw er; // Unhandled 'error' event
^
error: language "plpgsql" does not exist
at Connection.parseE (/opt/openerp/etherpad/etherpad-lite/src/node_modules/$
at Connection.parseMessage (/opt/openerp/etherpad/etherpad-lite/src/node_mo$
at Socket.<anonymous> (/opt/openerp/etherpad/etherpad-lite/src/node_modules$
at Socket.EventEmitter.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:746:14)
at Socket.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:408:10)
at emitReadable (_stream_readable.js:404:5)
at readableAddChunk (_stream_readable.js:165:9)
at Socket.Readable.push (_stream_readable.js:127:10)
RESTART!
In other servers I didn't have such problem using PostgreSQL with Etherpad.
I created database using this command:
crate database etherpad WITH TEMPLATE template0;
My configuration in etherpad is like this:
"dbType" : "postgres",
"dbSettings" : {
"user" : "db_user",
"host" : "localhost",
"password": "my_password",
"database": "etherpad"
},
Everything else is left unchanged, except I commented dirty db settings.
P.S. with dirty db it works.
If you are using 9.1 and below, you should CREATE LANGUAGE plpgsql in template1, and then create your database based on that template. This should not happen or be required on PostgreSQL 9.2 and above.

How do I add a gem to a group from within a Thor task?

I'm in a Thor task where I'd like to add gems to the assets group in my gem file (see below).
The gem_group command (known from standard Rails App Templates) doesn't seem work in a Thor task (see error at bottom).
How could i best add a gem to a group in the gem file from within a Thor task?
Any thought welcome - thanks.
class ThorBuild < Thor
desc "add_gems", "Adds the gems I need"
def add_gems
puts "Running add_gems"
gem 'mongoid', '~> 3.0.15'
gem 'bson_ext'
gem 'less-rails'
gem 'devise'
gem_group :assets do
gem 'therubyracer', '= 0.10.0', :platforms => :ruby
gem 'twitter-bootstrap-rails'
end
end
end
The output looks like this ...
Running add_gems
/home/ubuntu/sites/ThorBuild.thor:12:in `add_gems': undefined method `gem_group' for #<Thor::Sandbox::ThorBuild:0x000000007b5110> (NoMethodError)
from /home/ubuntu/.rvm/gems/ruby-1.9.3-p327/gems/thor-0.16.0/lib/thor/task.rb:27:in `run'
from /home/ubuntu/.rvm/gems/ruby-1.9.3-p327/gems/thor-0.16.0/lib/thor/invocation.rb:120:in `invoke_task'
from /home/ubuntu/.rvm/gems/ruby-1.9.3-p327/gems/thor-0.16.0/lib/thor.rb:275:in `dispatch'
from /home/ubuntu/.rvm/gems/ruby-1.9.3-p327/gems/thor-0.16.0/lib/thor/base.rb:425:in `start'
from /home/ubuntu/.rvm/gems/ruby-1.9.3-p327/gems/thor-0.16.0/lib/thor/runner.rb:36:in `method_missing'
from /home/ubuntu/.rvm/gems/ruby-1.9.3-p327/gems/thor-0.16.0/lib/thor/task.rb:29:in `run'
from /home/ubuntu/.rvm/gems/ruby-1.9.3-p327/gems/thor-0.16.0/lib/thor/task.rb:126:in `run'
from /home/ubuntu/.rvm/gems/ruby-1.9.3-p327/gems/thor-0.16.0/lib/thor/invocation.rb:120:in `invoke_task'
from /home/ubuntu/.rvm/gems/ruby-1.9.3-p327/gems/thor-0.16.0/lib/thor.rb:275:in `dispatch'
from /home/ubuntu/.rvm/gems/ruby-1.9.3-p327/gems/thor-0.16.0/lib/thor/base.rb:425:in `start'
from /home/ubuntu/.rvm/gems/ruby-1.9.3-p327/gems/thor-0.16.0/bin/thor:6:in `<top (required)>'
from /home/ubuntu/.rvm/gems/ruby-1.9.3-p327/bin/thor:19:in `load'
from /home/ubuntu/.rvm/gems/ruby-1.9.3-p327/bin/thor:19:in `<main>'
from /home/ubuntu/.rvm/gems/ruby-1.9.3-p327/bin/ruby_noexec_wrapper:14:in `eval'
from /home/ubuntu/.rvm/gems/ruby-1.9.3-p327/bin/ruby_noexec_wrapper:14:in `<main>'

How do I get mongoid's eager loading to work?

I get the following error:
NoMethodError (undefined method `eager_load' for nil:NilClass)
when I run the following command in Mongoid 2.2.1
Person.includes(:game).all.each do
user.game.dosomething
end
a Person has_one Game
Just turn on Identity Map: http://mongoid.org/en/mongoid/docs/identity_map.html
Try add this to your Gemfile
# gem "mongoid-eager-loading"
But note that it's deprecated in newer mongoid versions

Rails 3, sqlserver, using set_primary_key, and inability to find with a specific ID

I'm trying to port a Rails2 application over to Rails3 - this app provides a front-end to multiple databases, one of which is SQL Server 2005. The SQL Server 2005 database is legacy so I have to use set_table_name and set_primary_key as such:
class Project < ActiveRecord::Base
set_table_name "SpiraTest.TST_PROJECT"
set_primary_key "PROJECT_ID"
end
Firing up the console I can see
irb(main):002:0> Project.primary_key
=> "PROJECT_ID"
irb(main):003:0> Project.table_name
=> "SpiraTest.TST_PROJECT"
irb(main):004:0>
I can even use Project.find(:first), Project.find(:last), etc. and retrieve the data. What I can't do is find using an id, like this: Project.find(1). I get met with:
NoMethodError: undefined method `eq' for nil:NilClass
from /usr/lib/ruby/gems/1.8/gems/activesupport-3.0.9/lib/active_support/whiny_nil.rb:48:in `method_missing'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/active_record/relation/finder_methods.rb:317:in `find_one'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/active_record/relation/finder_methods.rb:292:in `find_with_ids'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/active_record/relation/finder_methods.rb:107:in `find'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/active_record/base.rb:444:in `__send__'
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.9/lib/active_record/base.rb:444:in `find'
from (irb):4
irb(main):005:0>
I have been looking down through the finder_methods and can see where in the find_one method that
record = where(primary_key.eq(id)).first
'primary_key' is nil.
I'm at a loss on this - I'll continue to hunt and see what I find.
Gems being used for completeness:
gem 'rails', '3.0.9'
gem 'mysql2', '< 0.3'
gem 'activerecord-sqlserver-adapter'
gem 'mongrel'
gem 'psrutil'
gem 'net-ldap'
gem 'spreadsheet'
gem 'ruby-odbc'
Make sure to use set_primary_key and note, it is case sensitive.

Resources