I am migrating my Ruby (1.8.7) Rails (2.3.18) application database into MSSQL-2012 Database.
I have followed all the configuration information and made. The Sql adapter I am using is activerecord-sqlserver-adapter (2.3.24).
When I load the application I got a error. The error says " The current version support only Mssql 2005,2008 " error.
How can I proceed, As of now I can't upgrade or downgrade my Ruby on Rails versions and MSSQL versions.
Is this any way is there to proceed with current set up and versions . Plz help me
Sounds like you just need to update your adapter. Looking at the Github page, it should support 2012
https://github.com/rails-sqlserver/activerecord-sqlserver-adapter
So, if you haven't figured out a way to fix this yet, you can create a new initializer file and drop the following code in it.
module ActiveRecord
module ConnectionAdapters
class SQLServerAdapter
alias :old_initialize :initialize
def initialize(logger, config)
begin
old_initialize(logger, config)
rescue NotImplementedError => e
unless e.message =~ /Currently, only #{SUPPORTED_VERSIONS.to_sentence} are supported./
raise e
end
end
end
def sqlserver_2012?
#database_year == 2012
end
end
end
end
Unfortunately there's no driver for SQL Server 2012 and rails 2.x
You need to upgrade to Rails 3.2, as this is the first version of the SQL Server gem that supports 2012.
You can take a look at the docs to check the different versions.
Related
I am trying to update a gem called textacular to be compatible with latest rails version.
In the development Rake-tasks we need to run a few ActiveRecord migrations - without Rails.
Today it looks like:
namespace :migrate do
desc 'Run the test database migrations'
task :up => :'db:connect' do
ActiveRecord::Migrator.up 'db/migrate'
end
desc 'Reverse the test database migrations'
task :down => :'db:connect' do
ActiveRecord::Migrator.down 'db/migrate'
end
end
However when using ActiveRecord >= 5, it fails with:
NoMethodError: undefined method 'up' for ActiveRecord::Migrator:Class.
I have tried to look through the source code for ActiveRecord, tried a bunch of different methods but have not managed to run the migrations.
Does anyone have a hint of what to do?
Edit
Using ActiveRecord::Migration.up does nothing, probably just returns based on the method.
Using ActiveRecord::Migration.migrate(:up) gives output:
== ActiveRecord::Migration: migrating ========================================
== ActiveRecord::Migration: migrated (0.0000s) ===============================
All migrations are in the folder db/migrate.
You can also use this command:
ActiveRecord::MigrationContext.new(Rails.root.join('db', 'migrate'), ActiveRecord::SchemaMigration).migrate
I managed to solve this (until Rails 6 is release at least), the implementation can be seen on textacular
task :up => :'db:connect' do
migrations = if ActiveRecord.version.version >= '5.2'
ActiveRecord::Migration.new.migration_context.migrations
else
ActiveRecord::Migrator.migrations('db/migrate')
end
ActiveRecord::Migrator.new(:up, migrations, nil).migrate
end
Not very satisfied with this solution, but this was the only way I could get the migrations to run on Rails 5, 5.1 and 5.2.
By looking at the rails github page then starting from Rails 5.2 the Migrator class is cut down quite a bit. Much of its methods have moved to Migration class instead (including the .up method).
Therefore just replace ActiveRecord::Migrator with ActiveRecord::Migration.
I have a rails application. Rails version is 2.3.4 and ruby version 1.8.7. In that application I used geokit (1.5.0) gem and geokit-rails plugin to find nearest location.
And in my model I have code like this,
class Notary < ActiveRecord::Base
acts_as_mappable
end
And in my controller have code like this,
class Client::OrdersController < ApplicationController
def find_notary
#order = Order.find(params[:id])
#miles = 10
unless params[:notary_search]
#notaries = Notary.find(:all, :origin => #order.signing_location_zip_code, :within => #miles, :conditions => "on_vacation IS NOT true",:order=>"distance asc" )
else
some code
end
end
end
I am getting error in that line
#notaries = Notary.find(:all, :origin =>
#order.signing_location_zip_code, :within => #miles, :conditions =>
"on_vacation IS NOT true",:order=>"distance asc") like this,
Geokit::Geocoders::GeocodeError in
Client/ordersController#find_notary
Geokit::Geocoders::GeocodeError
RAILS_ROOT: /home/user/svnnew_app/trunk/app
Application Trace | Framework Trace | Full Trace
/home/user/.rvm/gems/ruby-1.8.7-p371#app/gems/geokit-1.5.0/lib/geokit/mappable.rb:282:in
`normalize'
/home/user/svnnew_app/trunk/app/vendor/plugins/geokit-rails/lib/geokit-rails/acts_as_mappable.rb:347:in
`normalize_point_to_lat_lng'
/home/user/svnnew_app/trunk/app/vendor/plugins/geokit-rails/lib/geokit-rails/acts_as_mappable.rb:306:in
`extract_origin_from_options'
/home/user/svnnew_app/trunk/app/vendor/plugins/geokit-rails/lib/geokit-rails/acts_as_mappable.rb:203:in
`prepare_for_find_or_count'
/home/user/svnnew_app/trunk/app/vendor/plugins/geokit-rails/lib/geokit-rails/acts_as_mappable.rb:108:in
`find'
/home/user/svnnew_app/trunk/app/app/controllers/client/orders_controller.rb:331:in
`find_notary'
Request
Parameters:
{"id"=>"1198"}
Show session dump Response
Headers:
{"Cache-Control"=>"no-cache", "Content-Type"=>""}
How to resolve this error? Please help me out..
I maintain geokit. I had a look at the source code and that line happens when the response back from the API isn't numeric, e.g. a string but not in the format '99.99, 88.88', so would happen if the geocoding API returned 'NA' or something for example.
And I know StackOverflow says "avoid" the following (clarification, opinion, etc.), but here it is:
I can't help further without you doing a few things:
1) If you could update to the latest geokit (gem: 1.7.1 or the latest github master)
2) Do some debugging, e.g. Open "/home/user/.rvm/gems/ruby-1.8.7-p371#app/gems/geokit-1.5.0/lib/geokit/mappable.rb" (line 282) and least "puts" the string that is causing the error along with any other relevant local variables.
Using gems like pry/pry-debugger are a must for any ruby developer to debugging such issues.
3) Update other software where possible (even upgrade to latest ruby 1.8.7 and rails 2.x)
You're ruby (1.8.7) and rails (2.x) both are quite old and contain various security issues which should be of some concern. I do my best to keep geokit/geokit-rails working with ruby 1.8.7, but even rails 2 compatibility was dropped in geokit-rails, although I'm happy to help because likely you issue is a problem in geokit-rails with supported rails versions.
I developed a server in C++ and I would like to develop an interface in Ruby On Rails.
So I started to read http://ruby.railstutorial.org/, meanwhile I start looking if I would be able to create a connection between my Ruby On Rails application and my server.
I find out I could use TCPSocket.
My question is : Could I open just 1 TCPSocket by session (and store it somewhere) ?
Or would I have to open a TCPSocket for every action in my controllers ?
Thanks in advance,
app/models/conn.rb:
class Conn
#connection = "foo" # Connect here
def self.get_connection
#connection
end
end
Rails console:
irb(main):002:0> Conn.get_connection
=> "foo"
But unless your server is single-threaded you will have more than one connection anyways.
I am apparently having a huge problem switching from the plugin version of Paperclip to the gem version in my app. It's been my impression that there should be no difference whatsoever between a plugin and a gem of a specified version. However, I'm not seeing this as an easy transition at all.
Rails 2.3.11, Ruby 1.8.7
The plugin version I am using is version 2.3.3 and was upgraded on August 2, 2010. Attempting to update this to the gem of the same version basically killed all my tests, not being able to load a factory model which did not have its attachment loaded. It appeared that validate_attachment_content_type was also attempting to validate the attachment presence, and couldn't find it, so everything just started breaking. Again, with the plugin there are no problems and I haven't had any problems in all this time we've been using it. On the other hand, this problem seems to not occur past version 2.3.4. That's a whole other set of problems.
Basically, in all versions from 2.3.4 and up I get the problem below:
can't convert nil into String
/home/joshua/.rvm/gems/ruby-1.8.7-p334#paperclip_upgrade/gems/paperclip-2.3.15/lib/paperclip/storage/s3.rb:163:in `extname'
/home/joshua/.rvm/gems/ruby-1.8.7-p334#paperclip_upgrade/gems/paperclip-2.3.15/lib/paperclip/storage/s3.rb:163:in `to_file'
/home/joshua/.rvm/gems/ruby-1.8.7-p334#paperclip_upgrade/gems/paperclip-2.3.15/lib/paperclip/attachment.rb:94:in `assign'
/home/joshua/.rvm/gems/ruby-1.8.7-p334#paperclip_upgrade/gems/paperclip-2.3.15/lib/paperclip.rb:279:in `avatar='
/home/joshua/railscamp/app/app/models/organization.rb:311:in `copy_membership'
in all my tests that access my organization model.
The apparent offending code in this case is attempting to clone a membership model from one organization to another, with the * line being the offending call.
def copy_membership(membership)
m = membership.clone
u = m.user.clone
u.organization = self
m.organization = self
begin
m.avatar = membership.avatar *
rescue RuntimeError
m.avatar = nil
end
m.user = u
m.save
m
end
Does this make any sense to anyone? Why would the plugin work, but the gem of the same version just wrecks everything?
Update: I also don't appear to have any paperclip rake tasks available. Any ideas?
As it turns out, we should have been checking whether the filename is valid or not, rather than depending on a generic runtime error for detecting avatar presence.
I have a Rails app that I'm porting from Rails 1.2 to 2.3. I'm also moving from the Ruby MRI to the latest version of JRuby as well.
In the existing (Rails 1.2) app I use the mysql_bigint plugin to provide support for 64-bit ints as primary keys.
I need to to the same thing for the new application running against a MS SQL 2005 database server.
I'm not sure if the snippet here would help: using UUID as primary key in rails and polymorph relationships
Any ideas where to start?
TIA
Dave
Add this to config/environment.rb:
module JdbcSpec
module MsSQL
def modify_types(tp)
super(tp)
tp[:primary_key] = "bigint NOT NULL IDENTITY(1, 1) PRIMARY KEY"
tp
end
end
end