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. You might consider including the SQL Anywhere Ruby API reference as part of your familiarization with Ruby.
If you are ready to jump into Rails development, there are a few things you need to do.
RubyGems You should install RubyGems. It simplifies the installation of Ruby packages. At the time of writing, version 1.3.1 was required for Rails development. The Ruby on Rails web site 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 web site recommends which version to install.
Rails With RubyGems, you can install all of Rails and its dependencies with a single command line:
gem install rails |
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.
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 2.2.2 of Rails, then the path to this file would be \Ruby\lib\ruby\gems\1.8\gems\rails-2.2.2\configs\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 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 database: <%= app_name %>_test username: DBA password: sql production: adapter: sqlanywhere database: <%= app_name %>_production username: DBA password: sql |
You must update the Rails app_generator.rb file. Using the same assumptions in step 1 above, this file is located in the path \Ruby\lib\ruby\gems\1.8\gems\rails-2.2.2\lib\rails_generator\generators\applications\app. Edit the app_generator.rb file and locate the following line:
DATABASES = %w(mysql oracle postgresql sqlite2 sqlite3 frontbase ibm_db) |
Add sqlanywhere to the list as follows.
DATABASES = %w(sqlanywhere mysql oracle postgresql sqlite2 sqlite3 frontbase ibm_db) |
If you want, you can also change the DEFAULT_DATABASE setting (on the next line) to read as follows:
DEFAULT_DATABASE = 'sqlanywhere' |
Now save the file and exit.
It is recommended that you start with the tutorial on the Ruby on Rails website. 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 blog -d sqlanywhere |
If you changed the DEFAULT_DATABASE setting, then the -d sqlanywhere
option is not required.
Also, note that the blog tutorial requires that you set up three databases. After you have initialized the project, you can change to the root directory of the project and create three databases as follows.
dbinit blog_development dbinit blog_test dbinit blog_production |
Before you continue, you must start the database server and the three databases as follows.
dbsrv12 blog_development.db blog_production.db blog_test.db |
You are now ready to explore Ruby on Rails web development using the tutorial.
For more information about the Ruby on Rails web development framework, see http://www.rubyonrails.org/.
Discuss this page in DocCommentXchange.
|
Copyright © 2010, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.0 |