You can configure Ruby on Rails support in SQL Anywhere.
Prérequis
There are no prerequisites for this task.
Install RubyGems. It simplifies the installation of Ruby packages. The Ruby on Rails download page directs you to the correct
version to install. See http://www.rubyonrails.org/.
Install the Ruby interpreter on your system. The Ruby on Rails download page recommends which version to install. See http://www.rubyonrails.org/.
Install Ruby Rails and its dependencies by running the following command:
gem install rails |
Install the Ruby Development Kit (DevKit). Download the DevKit from http://rubyinstaller.org/downloads/ and follow the instructions at
http://github.com/oneclick/rubyinstaller/wiki/Development-Kit.
Install the SQL Anywhere ActiveRecord support (activerecord-sqlanywhere-adapter) by running the following command:
gem install activerecord-sqlanywhere-adapter |
Add SQL Anywhere to the set of database management systems supported by Rails. At the time of writing, Rails 3.1.3 was the current released version.
Configure a database by creating a sqlanywhere.yml file in the Rails configs\databases directory. If you have installed Ruby in the \Ruby directory and you have installed version 3.1.3 of Rails, then the path to this file would be \Ruby\lib\ruby\gems\1.9.1\gems\railties-3.1.3\lib\rails\generators\rails\app\templates\config\databases. The contents of this file should be:
# # SQL Anywhere database configuration # # This configuration file defines the patten used for # database filenames. If your application is called "blog", # then the database names will be blog_development, # blog_test, blog_production. The specified username and # password should permit DBA access to the database. # development: adapter: sqlanywhere server: <%= app_name %> database: <%= app_name %>_development username: DBA password: sql # 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: adapter: sqlanywhere server: <%= app_name %> database: <%= app_name %>_test username: DBA password: sql production: adapter: sqlanywhere server: <%= app_name %> database: <%= app_name %>_production username: DBA password: sql |
The sqlanywhere.yml file provides a template for creating database.yml files in Rails projects. The following database options can be specified:
adapter (required, no default). This option must be set to sqlanywhere to use the SQL Anywhere ActiveRecord adapter.
database (required, no default). This option corresponds to DatabaseName in a connection string.
server (optional, defaults to the database option). This option corresponds to ServerName in a connection string.
username (optional, defaults to 'DBA'). This option corresponds to UserID in a connection string.
password (optional, defaults to 'sql'). This option corresponds to Password in a connection string.
encoding (optional, defaults to the OS character set). This option corresponds to CharSet in a connection string.
commlinks (optional). This option corresponds to CommLinks in a connection string.
connection_name (optional). This option corresponds to ConnectionName in connection string.
Update the Rails app_base.rb file. Using the same assumptions in the previous step, this file is located in the path \Ruby\lib\ruby\gems\1.9.1\gems\railties-3.1.3\lib\rails\generators\app_base.rb. Edit the app_base.rb file and locate the following line:
DATABASES = %w( mysql oracle postgresql sqlite3 frontbase ibm_db sqlserver ) |
Add sqlanywhere to the list as follows:
DATABASES = %w( sqlanywhere mysql oracle postgresql sqlite3 frontbase ibm_db sqlserver ) |
Follow the tutorial on the Ruby on Rails web site ( http://guides.rails.info/getting_started.html) using the following SQL Anywhere-specific notes:
In the tutorial, you are shown the command to initialize the blog project. Here is the command to initialize the blog project for use with SQL Anywhere:
rails new blog -d sqlanywhere |
After you create the blog application, switch to its folder to continue work directly in that application:
cd blog |
Edit the gemfile file to include a gem directive for the SQL Anywhere ActiveRecord adapter. Add the new directive following the indicated line below:
gem 'sqlanywhere' gem 'activerecord-sqlanywhere-adapter' |
The config\database.yml file references the development, test, and production databases. Instead of using a rake command to create the databases as indicated by the tutorial, change to the db directory of the project and create three databases as follows.
cd db dbinit -dba DBA,sql blog_development dbinit -dba DBA,sql blog_test dbinit -dba DBA,sql blog_production cd .. |
![]() |
Discuter à propos de cette page dans DocCommentXchange.
|
Copyright © 2013, SAP AG ou société affiliée SAP - SAP Sybase SQL Anywhere 16.0 |