25/12/2010 --saturday
today we celebrate christmas in our office and we cut the cake and celebrate lots of fun in our office
today our guru chandrashekar sir told the introduction to rails
rails features
today our sir told class responsibilites colloborators
crc (vs) data flow diagram
sir told the difference between them
to generate a model in rails
--------------------------------
rails generate model user
name:string email:string password:string
to check the db
---------------
less config | database.yml
rake db:migrate
to check db exists (or) not
---------------------------
rails dbconsole
rails 3 has an inbuilt nice feature of "sqlite" light weighted database
sqlite> .tables this command will show the list of all tables
sqlite>.schema users to see the users structure
sqlite>.quit --------> to quit the sqlite
to start a server
------------------
rails server
another terminal
---------------------------
cd rails again cd tu
like Irb rails console
-----------------------
u= user.new
u.name="john"
u.password="john123"
u.email="john@doe.com"
u
u.save!
the above lines stating that creating a new user and assigning a password and email id
and save the rails application
another terminal
-----------------------
to show rails console
SELECT *from users
sqlite>
u=user.new:name=>'smith':password=>'smith123':email=>'smith@yahoo.com'
u.save
SELECT *from users
u=user.find-by-name("john")
users=users.find:all //it will find all records
users[0].name
users[1].name
users=user.find:all,:conditions=>{:name=>'john'}
users=user.find:first,:conditions=>{:name=>'john'}
-----------------------------------------------------------------
vi app/models/user.rb
class User<activeRecord ::Base
.validates:name,:presence=>true
.validates:name,:uniqueness=>true
.validates:name,:length=>{:maximum=>32}
end
and sir also told ....best guides to ruby on rails
www.api.rubyonrails.org
No comments:
Post a Comment