Your SlideShare is downloading. ×
0
Beginners' guide to Ruby on Rails
Beginners' guide to Ruby on Rails
Beginners' guide to Ruby on Rails
Beginners' guide to Ruby on Rails
Beginners' guide to Ruby on Rails
Beginners' guide to Ruby on Rails
Beginners' guide to Ruby on Rails
Beginners' guide to Ruby on Rails
Beginners' guide to Ruby on Rails
Beginners' guide to Ruby on Rails
Beginners' guide to Ruby on Rails
Beginners' guide to Ruby on Rails
Beginners' guide to Ruby on Rails
Beginners' guide to Ruby on Rails
Beginners' guide to Ruby on Rails
Beginners' guide to Ruby on Rails
Beginners' guide to Ruby on Rails
Beginners' guide to Ruby on Rails
Beginners' guide to Ruby on Rails
Beginners' guide to Ruby on Rails
Beginners' guide to Ruby on Rails
Beginners' guide to Ruby on Rails
Beginners' guide to Ruby on Rails
Beginners' guide to Ruby on Rails
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Beginners' guide to Ruby on Rails

4,610

Published on

Published in: Technology
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
4,610
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
82
Comments
0
Likes
5
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Ruby on Rails<br />Server-side web development <br />VladStoian<br />Victor Porof<br />
  • 2. What we’ll talk about<br />What is Ruby on Rails?<br />A brief history<br />MVC architecture in a nutshell<br />Distinctive framework features<br />Why Ruby? Why Rails?<br />Demo<br />
  • 3. What is RoR?<br />Open Source<br />Abstraction providing generic server-side functionality<br />Used for web application development<br />It’s a framework for the Ruby language<br />..so don’t confuse it with plain Ruby!<br />
  • 4. A brief history<br />Originates in David Heinemeier Hansson’s work<br />First released in July 2004<br />Apple ships RoR with Mac OS X Leopard since 2007<br />Major new developments with v2.3 in 2009<br />Templates<br />Generate skeleton applications<br />Custom gems and configurations<br />Latest: v3.0.5, 27 February 2011<br />
  • 5. MVC architecture<br />RoR is based on the Model-View-Controller design<br />It’s an architectural development pattern<br />Widely used in many other frameworks:<br />Oracle Application Framework, Cocoon, JSF (Java)<br />ASP.NET (C#)<br />SproutCore, JavascriptMVC (Javascript)<br />Django, Pylons (Python)<br />CakePHP(PHP)<br />PureMVC (many languages)<br />
  • 6.
  • 7. MVC on Rails<br />Models are Ruby classes, used to store and validate data<br />Handles migrations<br />They talk to databases<br />MySQL<br />SQLite<br />PostgreSQL<br />NoSQL<br />MongoDB<br />Cassandra<br />“Chubby guy in the back room” crunching the numbers<br />
  • 8. Model snippet<br />class Person < ActiveRecord::Base<br />validates_presence_of :name<br />has_many :wifes<br />end<br />Person.create(:name => ”Muhammad Ali”).valid? # => true<br />Person.create(:name => nil).valid? # => false<br />
  • 9. Migration snippet<br />class AddReceiveNewsletterToUsers < ActiveRecord::Migration<br />defself.up<br />change_table :users do |t|<br />t.boolean :receive_newsletter, :default => false<br /> end<br />User.update_all ["receive_newsletter = ?", true]<br /> end<br />defself.down<br />remove_column :users, :receive_newsletter<br /> end<br />end<br />
  • 10. MVC on Rails<br />What the user sees<br />HTML, CSS, XML, Javascript (jQuery)<br />JSON, RSS, Atom<br />Automatically generated “view-puppets”<br />Visual representation of data<br />Does not have direct access to the model!<br />It shouldn’t do lots of processing or calculation<br />
  • 11. View snippet<br /> <!-- app/views/items/new.rhtml --><br /> <%= form_tag :action => “create” %><br /> Name: <%= text_field“item”, “name”%><br/><br />Email: <%= text_field“item”, ”email”%><br/><br /> Password: <%= hidden_field “item”, “password”%><br/><br /> <%= submit_tag %><br /> <%= end_form_tag %><br />
  • 12. MVC on Rails<br />Gateway between the model and the view<br />Handles user requests<br />Does parsing and data submissions<br />Takes care of sessions, cookies<br />Works out what data to show and what views to render<br />”The best controller: it gives orders without knowing (or caring) how it gets done”<br />
  • 13. Controller snippet<br />classItemsController < ApplicationController<br /> def edit<br /> @item = Item.find(params[:id])<br />ifrequest.post? <br /> @item.update_attributes(params[:item])<br />redirect_to :action => 'edit', :id => @item.id<br /> end<br /> end<br /> end<br />
  • 14. MVC on Rails<br />To summarize:<br />Keep your view code skinny<br />Keep your controller code skinny<br />The fatness is in the model<br />
  • 15. Framework features<br />Code generators<br />Awesome built-in functions => rapid development<br />Tons of “gems” to choose from<br />Cross-platform compatibility<br />Automated operation (CRUD)<br />Create, Retrieve, Automate and Delete<br />Simplified testing (Rake script)<br />
  • 16. Code generator snippet<br />#model generator (general)<br />ruby script/generate model model_name (v2.3)<br />rails generate model model_name (v3)<br />#model generator (example)<br />rails generate model user name:stringhashed_password:string<br />#controller generator (general)<br />ruby script/generate controller controller_namemethod_name(s) (v2.3)<br />rails generate controller controller_namemethod_name(s) (v3)<br />#controller generator (example)<br />rails generate controller store index<br />
  • 17. RoR servers<br />Mongrel<br />Webbrick<br />Thin<br />Apache (mod_passanger)<br />..so it’s very scalable!<br />
  • 18. Famous projects on Rails<br />Twitter (microblogging)<br />Crunchbase (companies database)<br />BaseCamp (project management)<br />Hulu (online tv)<br />Yellowpages.com (phone database)<br />Xing (business network)<br />
  • 19. Why Ruby?<br />Interpreted language => greater flexibility<br />Provides JIT (just in time compilation)<br />Garbage collection<br />Able to generate code on the fly<br />Cleaner syntax (no more “Verbose verbose is too verbose for verbose”)<br />Many implementations:<br />Jruby, IronRuby, Rubinius (Ruby & C++), MacRuby (ObjC)<br />
  • 20. Why Rails?<br />Based on Ruby<br />Easy to implement CGI scripts<br />Rapid web-application development<br />Designed to make programming work easier<br />Less coding, more functionality<br />Thousands of plugins<br />Don’t reinvent the wheel<br />
  • 21.
  • 22. Creating a blog with<br />

×