Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Standard view
Full view
of .
Look up keyword
Like this
0 of .
Results for:
No results containing your search query
P. 1
ActiveRecord 1

ActiveRecord 1



|Views: 498|Likes:
Published by Sumanth Krishna
This document aims to give intro to activerecord pattern and it's implementation in Rails (FrameWork)
This document aims to give intro to activerecord pattern and it's implementation in Rails (FrameWork)

More info:

Published by: Sumanth Krishna on Mar 19, 2008
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less





Ruby on Rails
ActiveRecord in RailsDatabase Connectivity Rails Way
Sumanth Krishna. ABlog: TechSavvyhttp://sumanthtechsavvy.blogspot.comSumanth Krishna. A
Ruby on Rails
We always talk about programming languages and we take pride in propagating how thelanguage follows/supports the object oriented paradigm. This really makes sense, since we can connectthem to real time objects. But, what about the databases? All the web applications do require somedatabases to store the content, user information and so on. We alway depend on database for any kindof information, but
Are our databases are ready to listen to objects?How the languages communicate to the database (nothing but content)?
Well this is where the Active Record pitches in: Active record is an approach that is used to access thedata.
How it does?
Programming Language Database
class =====> tableobject =====> single row in table properties/methods =====> columns in table
"A database table or viewis wrapped into aclass,thus an objectinstance is tied to a single row in the table. After creation of an object, a new row is added to the table upon save. Any object loaded gets itsinformation from the database; when an object is updated, the corresponding row in the table is alsoupdated. Thewrapper classimplements accessor methods or properties for each column in the table or view." Now that is with Active record. Rails do implement the same pattern and with power of ruby, it doesadd some extra features/conventions to make developers life simpler.Well in following posts we will see,1.How active record is implemented in rails2.What are the conventions?3.How to configure database to rails applications?4.Do we need to write xml files to configure each table?Sumanth Krishna. A
Ruby on Rails
One of the main features that rails do support on isConvention over Configuration. Well repeatagain and again Convention over Configuration. Let it get into the minds!Well it is spread across the rails framework with which will be developing an application. I will bereminding whenever it's put in use.In previous post, I did stress on how simple it would be in configuring the databases and tables withyour application. In Java based applications, this would be done using lot of xml files, which is of course, time taking, lot of repetitive work and error prone... (at least that's what my friend's used tosay!).Well in rails this is not the case a simple convention that you follow would ensure of configuring thetables of databases."You name the tables in database as plurals and create classes with singular form of thetable names."Configuring the Databases:The choice of which database you use the configuration and respective adapter would depend on. Whenwe created an application, there is a set of predefined folders created over a simple command! (I willtouch upon this later). "config" is one such folder and under this we will now concentrate/repair on"database.yml".Rails would automatically create 3 different environments:1.Development2.Test3.ProductionBased on the environment we work on we need to edit the data accordingly. (More onenvironments will be covered sooner!)This file contains the information relate to the adapter, database, user credentials, host, port...This does make sense in a way, the plural form for tables will fit as it contains huge data and therespective class which we would be placed under app/models, with the extension ".rb" is named insingular form.
development:adapter: mysqldatabase: dummyusername: rootpassword: adminhost: localhostWhat it means?
Our application is connected to MySQL database by name dummy, user being and root and with anempty password. The host environment is "localhost".Sumanth Krishna. A

Activity (6)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
mubitag liked this
mubitag liked this
Wayne Wang liked this
Ravikumar liked this

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->