ruby on rails : first mile

32
“I always knew that one day Smalltalk would replace Java. I just didn’t know it would be called Ruby.” – Kent Beck, MountainWest RubyConf 2009

Upload: gourab-mitra

Post on 01-Sep-2014

1.160 views

Category:

Technology


0 download

DESCRIPTION

This was presented in a workshop series in 2010 at Birla Institute of Technology, Mesra (Ranchi). It was a 2 hour Ruby on Rails introduction and demo

TRANSCRIPT

Page 1: Ruby on Rails : First Mile

“I always knew that one day Smalltalk would replace Java. I just didn’t know it would be called Ruby.” – Kent Beck, MountainWest RubyConf 2009

Page 2: Ruby on Rails : First Mile

Ruby on Rails : First MileSujeet KumarGourab Mitra

Page 3: Ruby on Rails : First Mile

Ruby on Rails : Applications

Page 4: Ruby on Rails : First Mile

What is Ruby?o dynamic, reflective, general purpose object-oriented

programming languageo designed by Yukihiro "Matz" Matsumoto. It was influenced

primarily by Perl, Smalltalk, Eiffel, and Lisp.o Ruby supports multiple programming paradigms, including

functional, object oriented, imperative and reflective. It also has a dynamic type system and automatic memory management; it is therefore similar in varying respects to Python, Perl, Lisp, Dylan, Pike, and CLU.

o alternative implementations of the Ruby language, including YARV, JRuby, Rubinius, IronRuby, MacRuby, and HotRuby, each of which takes a different approach, with IronRuby, JRuby and MacRuby providing just-in-time compilation and MacRuby also providing ahead-of-time compilation

Page 5: Ruby on Rails : First Mile

What is Rails ?o open source web application framework for the Ruby

programming language.o It is intended to be used with an Agile development

methodology that is used by web developers for rapid development

o Ruby on Rails was extracted by David Heinemeier Hansson from his work on Basecamp, a project management tool by 37signals (now a web application company

o David Hansson first released Rails as open source in July 2004

Page 6: Ruby on Rails : First Mile

How Ruby helps RoR developerso By helping you know what the code in your

application is doingo By helping you do more in, and with, your Rails

applications that you can if you limit yourself to the readily available Rails idioms and techniques

o By allowing you to familiarize yourself with the Rails source code, which in turn enables you to participate in discussions about Rails and perhaps submit bugs and patches.

o By giving you powerful tool for administrative and organization tasks connected with your application.

Page 7: Ruby on Rails : First Mile

AgendaRuby ConceptsRuby for RailsRails ConceptsHello RoRFirst RoR AppFurther reading

Page 8: Ruby on Rails : First Mile

AgendaRuby ConceptsRuby for RailsRails ConceptsHello RoRFirst RoR AppFurther reading

Page 9: Ruby on Rails : First Mile

Ruby Concepts• Thinking in Ruby• IRB• Hello World

Page 10: Ruby on Rails : First Mile

AgendaRuby ConceptsRuby for RailsRails ConceptsHello RoRFirst RoR AppFurther reading

Page 11: Ruby on Rails : First Mile

AgendaRuby ConceptsRuby for RailsRails ConceptsHello RoRFirst RoR AppFurther reading

Page 12: Ruby on Rails : First Mile

Ruby for Rails• Ruby Constructs• Importance of Ruby• Extending Rails and other

frameworks

Page 13: Ruby on Rails : First Mile

AgendaRuby ConceptsRuby for RailsRails ConceptsHello RoRFirst RoR AppFurther reading

Page 14: Ruby on Rails : First Mile

AgendaRuby ConceptsRuby for RailsRails ConceptsHello RoRFirst RoR AppFurther reading

Page 15: Ruby on Rails : First Mile

Rails Concepts

• MVC• Server• Convention over Configuration• Structure of a Rails App• DRY(Don’t Repeat Yourself)• Migrations• Gems• Routes• And other topics

Page 16: Ruby on Rails : First Mile

MVC o Stands for Model-View-Controllero Model is responsible for maintaining the state of an

applicationo View layer provides the user interfaceof an application

Page 17: Ruby on Rails : First Mile

Servero WEBricko Mongrel

o > ruby script/servero > gem server

Page 18: Ruby on Rails : First Mile

Convention over Configuration

o All you need is common sense and it works like magic!

o Comparison with C# , Java

o No Connection String

Page 19: Ruby on Rails : First Mile

Structure of a Rails Appo Another example of

convention over configuration

o Advantageso > ruby script/console

Page 20: Ruby on Rails : First Mile

DRY (Don’t Repeat Yourself)

Implications of DRY in RoR ; migrations , seeds etc.

Page 21: Ruby on Rails : First Mile

Migrations1. Migrations are a convenient way for you to alter your

database in a structured and organized manner. You could edit fragments of SQL by hand but you would then be responsible for telling other developers that they need to go and run them. You’d also have to keep track of which changes need to be run against the production machines next time you deploy.

2. db/schema.rb3. Timestamp4. Use of migrations in case of faulty code generation

Page 22: Ruby on Rails : First Mile

Typical Migrationclass CreateProducts < ActiveRecord::Migration def self.up

create_table :products do |t| t.string :name t.text :description t.timestamps end

end def self.down

drop_table :products end end

Page 23: Ruby on Rails : First Mile

Custom Migrations> rake db:migrate VERSION=<timestamp>

> ruby script/generate migration Add<Field>To<ContollerName> fieldname:type

Page 24: Ruby on Rails : First Mile

Routeso routes.rbo map.root

Page 25: Ruby on Rails : First Mile

Gems1. > gem install <gem-name>2. > gem install <gem-name> --local3. > gem update –system4. > gem server5. From setup.rb … >ruby setup.rb6. From gemspec .. >gem build example.gemspec7. Get gemspecs / .gems form Rubyforge.com or

github8. Rake gem:install

Page 26: Ruby on Rails : First Mile

Rails gem dependencies

Page 27: Ruby on Rails : First Mile

Lets get to work …..Hello RoR

Page 28: Ruby on Rails : First Mile

Good! Now lets make something more practical..

Page 29: Ruby on Rails : First Mile

QUESTIONS ?? (just easy ones please)

Page 30: Ruby on Rails : First Mile

Important Websiteshttp://rubyonrails.orghttp://railsbrain.comhttp://railscasts.comhttp://asciicasts.comhttp://github.com

Page 31: Ruby on Rails : First Mile

Contacto Gourab Mitra [email protected] http://gourabmitra.co.cc

o Sujeet Kumar [email protected] http://bit.ly/aEFKTT

Page 32: Ruby on Rails : First Mile

THANK YOU