Rails is a web development framework written in the Ruby language. Its strength is in web application development. A familiarity with the Ruby programming language is highly recommended before you attempt Rails development. As part of becoming familiar with Ruby, you might consider reading SQL Anywhere Ruby API reference.
RubyGems You should 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/.
Ruby You must install the Ruby interpreter on your system. The Ruby on Rails download page recommends which version to install. See http://www.rubyonrails.org/.
Rails With RubyGems, you can install all of Rails and its dependencies with a single command line:
gem install rails |
Ruby Development Kit 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.
activerecord-sqlanywhere-adapter If you have not already done so, you must install the SQL Anywhere ActiveRecord support to do Rails development using SQL Anywhere. With RubyGems, you can install all of SQL Anywhere ActiveRecord support and its dependencies with a single command line:
gem install activerecord-sqlanywhere-adapter |
Once you have installed the requisite components, there are a few final steps that you must undertake before you can begin Rails development using SQL Anywhere. These steps are required to 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.
To configure a database, you must create a sqlanywhere.yml file in the Rails configs\databases directory. If you have installed Ruby in the path \Ruby 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 |
You must update the Rails app_base.rb file. Using the same assumptions in step 1 above, 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 ) |
Now save the file and exit.
The sqlanywhere.yml provides a template for creating database.yml files in Rails projects. The template above shows some of the database options that may be specified. Here is a complete list.
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.
It is recommended that you start with the tutorial on the Ruby on Rails website. Use the notes below in parallel with the tutorial. These notes outline any differences when using SQL Anywhere. For the Rails tutorial, see http://guides.rails.info/getting_started.html.
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 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' |
If you look at the contents of the config\database.yml file, you will see that it references 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 blog_development dbinit blog_test dbinit blog_production cd .. |
Before you continue, you must start the database server and the three databases as follows.
dbsrv12 -n blog blog_development.db blog_production.db blog_test.db |
The server name in the command line (blog) must match the name specified by the server: tags in the database.yml file. The sqlanywhere.yml template file is configured to ensure that the server name matches the project name in all generated database.yml files.
Discuss this page in DocCommentXchange.
|
Copyright © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1 |