Tutorials to .com

Tutorials to .com » Database » Oracle » Ruby on Rails applications on the Oracle

Ruby on Rails applications on the Oracle

Print View , by: iSee ,Total views: 17 ,Word Count: 2314 ,Date: Sun, 23 Aug 2009 Time: 3:59 AM

Rails is a framework to use, but like any technology, it needs to be proficient in a certain period of time. You may of Ruby on Rails has been heard, the new application framework is a tendency to heavy rain and strong wind swept the Web development community, in particular j2ee and php programming community.

Rails is a powerful Web application platform, in less than two years have won a number of J2EE and PHP programmers to a wide range of popular. Why it will be J2EE and PHP programmers favor? Understanding of the advantages of Rails doubt after your gone. One is its use of a strict model-view-controller (Model - View - Controller) architecture, won the self-esteem wrapped up in design mode and the "jump off" (self-technical fans) respect - this is the development of J2EE the reasons for their lovers. The second is the use of Rails can easily build a basic system - that is that it attracts the reasons for PHP developers.

However, the point of view from the database, Rails there are some very obvious flaws. Rails on the database and application needs of the layout of a number of assumptions were made. For example, Rails assumes that all tables are using a non-compound primary key. It does not support composite primary key! In addition, Rails does not support the two-step submission; it can only be used for the case of a single back-end database.

Rails is not the praise of this article or articles critical articles, this technology is only an introduction. Both of which have criticized the award. May sometimes seem a bit harsh criticism (in Rails, especially in the eyes of enthusiasts), but do not fooled by appearances. The use of any Web application framework should be about skills, whether it is J2EE, ASP.NET, or PHP. In the long run, the use of Rails other than the use of Web application development platform more efficient, but will take some time to acquaint themselves with and master the technology.

What is Ruby? What is Rails?

Ruby is a dynamic programming language, which in many ways similar to Perl, Python and Smalltalk, but it is self-contained. java and PHP programmers seem to be very easy to master the language, they are the greatest advocates of Ruby. This language has also attracted other people to join, including Don Box The Microsoft community super "jump-off."

Long history of Ruby, which came in 1993, prior to 1995 will be for the public to know the java and PHP. So even though Ruby is a mature language, but other languages as universal. This has resulted in a programming language Ruby camp, not as Java, PHP and Perl strong camp. Therefore, you may find the language-specific framework, libraries, books, websites, blog and other resources than less.

David Heinemeier Hanson at the launch in the near future after the Rails framework, Ruby capacity of poor communities to promote the trend has been reversed, there is evidence that the framework is the most popular since the birth of Ruby applications. Ruby programming language, Rails will be extended to extremely applicable to specific areas of Web development languages (Domain Specific Language). It also borrows to expand ActiveRecord to object-relational persistence introduced the Ruby language. Rails In addition to the reasons for people to turn away from it does not support composite primary key and two-step submission, its biggest obstacle is to use it you need to learn a programming language. This is not content with superficial understanding that most people can be a little stage and had to learn a new language can bring you joy, but at the same time is a formidable way of rough.

However, if you want to add their own curriculum vitaea, Ruby is the choice of language. Plum Blossom from the bitter cold to Shannon, Ruby is a completely free from the commercial interests of about 10 years after by the language of temper. Therefore, the use of Ruby can give you the enjoyment of pleasure, in many cases, their productivity than Java, C, and Microsoft. NET language of an order of magnitude higher. (IronPython could be an exception, it is the Python language and Microsoft. NET environment interface. Python similar to Ruby, high productivity is a dynamic programming language.)

What is the use of Rails?

Rails is a framework designed to start from scratch, using the relational database used to build the back-end dynamic Web site. Keywords will be the introduction of the Ruby programming language, simplifying the configuration of Web applications. In addition, it can be based on the existing database schema automatically produce a complete Web application, although a bit rough. This capability not only to highlight the advantages of Ruby, but is also its Achilles heel. Rails assumes that the database schema naming convention, if adhered to this norm, just the implementation of a command to generate a basic Web site. To complete this work but may require some additional configuration, and sometimes these configurations may not be met. Rail assume that you will find almost all of the database norms can change, but change the more the productivity of the lower platform. This is the Rails in the development of new databases to the new applicationreasons. But it is not the original system to deal with a very good program.

Example is the development of new understanding of the use of Rails applications, the best way. If you installed oracle database, and based on this database to create a new database and new table, then create a complete Web application will not be used more than 15 minutes. In this example, we will use Ruby on Rails to build a product catalog.

Example: a simple catalog

Last year I started to invest in high-grade comic books, especially since 1946, earlier versions of comic books. I created a simple Ruby on Rails database application, using it in my trading activities can be easy to insert, remove, change and delete books. Because it is for my personal use, so the procedure is of course to reductions. In this article want to build applications that I used Ruby on Rails application's "thin body" version.

Although Rails and Oracle databases can be used for many platforms, but this article uses Windows XP, there is evidence that it is the Oracle application developers, one of the most commonly used platform. This example is very simple, in fact, is the "Hello World" example of the programming language version of the database to enable you taste Ruby, but it does not display all the capabilities of the Rails, a programming language just like any "Hello World" examples are does not display most of the language, like all the capabilities.

If you run this example in the course of a problem, may have the following three reasons: the code is not downloaded; database set up properly, can not be connected to the sample application; or your Windows XP operating system problems. In the development process of this example, I met a number of related versions and database configuration problems - all of which are caused by lack of knowledge. I learned from my friend Michael Carland learned a lot of knowledge, this is the only way to successful completion of the sample, and make it as simple as possible.

The reality is, the realization of Ruby on Rails and Oracle's work is not a simple matter. People sometimes feel discouraged. For instance, as described by this article, you should not encounter problems. But once beyond the scope of this example will be a problem. Rails can achieve high productivity, but it is a command-line development environment, do not provide high-level integrated development environment usually have the "automatic" feature. If you are not "self-reliance"-type of technical personnel, it is best not to use the current Rails.

Step 1: set the Oracle database

If you combine the use of Rails and Oracle are not interested in, you will not look at this article, so you need to install an Oracle database instance to add a table of the database. Strictly follow the naming convention in this article is very important, otherwise Rails automatically generated by the code will not be able to function properly (if not adjusted). You want to create a table as follows:

CREATE TABLE comics (

id, NUMBER (10) NOT NULL,

title VARCHAR2 (60),

NUMBER (4),

publisher VARCHAR2 (60),

PRIMARY KEY (id)

);

CREATE SEQUENCE comics_seq;

Here provides a SQL script file, you can use it to create a table and add some product data. I suggest you use it, so that your application will be developed and be consistent here. The completion of this work the simplest way is to use the following steps in accordance with the SQL * Plus. (Assuming you have installed Oracle databases and know how to use it.)

The use of SQL * Plus, create a DBA user for the application in this operation.

SQL> GRANTdbaTOrubyIDENTIFIEDBYruby;

SQL> ALTERUSERrubyDEFAULTTABLESPACEusersTEMPORARYTABLESPACEtemp;

SQL> EXIT

SQL file used to create the application table COMICS, and then insert some sample data.

C: \> sqlplusruby / ruby @ rails@comics.sql

May you have found this case the COMICS to create the plural form, it seems that it is not normal, because usually we will table the singular form of the name (for example, COMIC). However, Rails uses the plural table name. Rails configuration can be changed through the default norm, but the name is more convenient to use the plural.

Step 2: Install Ruby, RubyGems, Rails and Rails Oracle database

Windows XP to use the Rails, requires two software: RubyGems with Ruby programming language of installation package, Rails 1.0 (1.1 version was recently launched, but only discussed in this article 1.0), and the Rails Oracle database library. To download and install with the Ruby installer Gems, please follow the steps below.

  • Visit http://rubyinstaller.rubyforge.org/.
  • Download "One-Click Ruby Installer".
  • Follow the instructions to complete the installation.

Ruby programming platform installed, you can use RubyGems is the Ruby applications framework to facilitate the installation of Ruby. To install the Rails application development framework, you need to do is open a command line prompt, type a command:

C: \> gemsinstallrails-v1.0.0--remote

Now that you have successfully installed Ruby, RubyGems and Rails, the next can be installed some special code in order to achieve Rails applications and Oracle database server communication. To download and install Oracle Rails database, please visit http://rubyforge.org/projects/ruby-oci8, download the ruby-oci8-0.1.13-mswin.r to c sites, and then in the command window the following command:

C: \> rubyruby-oci8-0.1.13-mswin.rb

If all goes well, so far, you completed the Ruby, Rails, and Rails-Oracle Link Library installation. The next step is to create your first Ruby on Rails Web applications.



Oracle Tutorial Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.