Intro to Rails and MVC

1,142 views

Published on

An introduction to Rails and its implementation of MVC

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,142
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
21
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Intro to Rails and MVC

  1. 1. An Introduction to Rails<br />
  2. 2. Ruby on Rails history<br />Ruby on Rails was extracted from 37signals’ Basecamp by David Heinemeier Hansson (DHH)<br />July 2004: first released as open source <br />Feb 2005: first external commit rights <br />Oct 2007: ships with Mac OS X v10.5 &quot;Leopard”<br />
  3. 3. Rails Philosophy<br /> Opinionated<br /> Convention over configuration<br /> DRY (Don&apos;t Repeat Yourself)<br />less code means it&apos;s easier to maintain & modify<br /> Test Driven Development (TDD)<br /> Minimal code - maximal effect<br />
  4. 4. Scaffold<br />Model<br />app/models/person.rb<br />db/migrate/20090611073227_create_people.rb<br />4 views<br />app/views/people/index.html.erb<br />app/views/people/show.html.erb<br />app/views/people/new.html.erb<br />app/views/people/edit.html.erb<br />Controller<br />app/controllers/people_controller.rb<br />route map.resources :people<br />
  5. 5. MVC<br />
  6. 6. MVC<br />Model: ActiveRecord<br />Represents what is in the database<br />View: ActionView, erb<br />Model rendered as HTML<br />Controller: ActionController<br />Receives HTTP actions (GET, POST, PUT, DELETE)<br />Decides what to do, typically rendering a view<br />
  7. 7. ActiveRecord<br />p = new Person<br />p = new Person(:first =&gt; &quot;May&quot;, :last =&gt; &quot;Fong&quot;)<br />p.save<br />p.save!<br />Person.create(:first =&gt; &quot;May&quot;, :last =&gt; &quot;Fong&quot;)<br />Person.create!(:first =&gt; &quot;May&quot;, :last =&gt; &quot;Fong&quot;)<br />

×