Connecting to an MSSQL database from a Ruby on Rails application running on Ubuntu

后端 未结 7 1447
名媛妹妹
名媛妹妹 2021-01-01 00:34

I have a situation where I\'m trying to build a web app which takes a total count of records in a table and outputs it to the screen. Sounds simple right...?

The mai

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-01 01:00

    A gem called active-record-sql-adapter lets you connect to an SQL Server db via ActiveRecord. You can do something like

    class RemodeDB
      establish_connection(:remote_db) #<=
      self.abstract_class = true # to avoid Rails' no associated model exception
    end
    

    then have your classes inherit the connection like so

    class Product < RemoteDB
       self.table_name ... 
    end
    

    Note that in order to connect to earlier versions of SQL Server (2005 in your case), you would need an earlier version of the gem which may not be compatible with your current version of Rails.

提交回复
热议问题