An Introduction to Ruby on Rails
Upcoming SlideShare
Loading in...5
×
 

An Introduction to Ruby on Rails

on

  • 2,928 views

Which ORM (Object-relational mapping) library should I use? What should I use for my template language? Should I use MVC (Model/View/Controller) or some other pattern? What unit testing framework ...

Which ORM (Object-relational mapping) library should I use? What should I use for my template language? Should I use MVC (Model/View/Controller) or some other pattern? What unit testing framework should I use? What database engine should I use?

Unfortunately, these questions make it difficult to start web projects. Therefore, Ruby on Rails has made all of these decisions already; you can just get started. And it's extensible enough that if one of the default choices doesn't work for you, just choose a different library. How does Ruby on Rails answer these questions? How does it use the Ruby language to help make your development even faster? Come and find out!

Statistics

Views

Total Views
2,928
Views on SlideShare
2,359
Embed Views
569

Actions

Likes
3
Downloads
48
Comments
0

5 Embeds 569

http://joefiorini.com 471
http://joefiorini.tumblr.com 85
http://feeds.feedburner.com 10
http://webcache.googleusercontent.com 2
http://translate.googleusercontent.com 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • TAKE IT SLOW <br /> Pause after topics <br /> Take some deep breaths <br /> Walk to other side of projector when pausing <br />
  • <br />
  • <br />
  • Within3 <br />
  • - Ecommerce Sites on Shopify <br /> - iPad/iPhone R&D <br /> - Consulting <br />
  • - Ecommerce Sites on Shopify <br /> - iPad/iPhone R&D <br /> - Consulting <br />
  • <br />
  • <br />
  • <br />
  • If I throw out a term that you don&#x2019;t understand, please feel free to ask! <br />
  • If I throw out a term that you don&#x2019;t understand, please feel free to ask! <br />
  • If I throw out a term that you don&#x2019;t understand, please feel free to ask! <br />
  • If I throw out a term that you don&#x2019;t understand, please feel free to ask! <br />
  • <br />
  • <br />
  • <br />
  • Write once, use everywhere <br /> Code is easier to consume <br /> Easier to edit later <br />
  • <br />
  • <br />
  • How many have not used MVC? <br /> <br /> It&#x2019;s up to you to architect and organize your code in those tools. Rails makes that decision for you by implementing MVC. <br />
  • <br />
  • Code driving the UI that gets displayed to the user <br />
  • Interacts with model and sends the data to the view <br />
  • - Open source framework for developing web applications <br /> - Created by David Heinemeier Hansson <br /> - 1.0 was an extremely opinionated framework <br /> - 3.0 allows you to change many of the opinions <br /> &#x2026;Written in the language <br />
  • - Everything has a type, but the language infers types at runtime instead of you specifying them up front <br />
  • <br />
  • <br />
  • <br />
  • Remembering names is not important; knowing how the pieces fit together & interact is <br />
  • <br />
  • <br />
  • <br />
  • Utility collection and standard Ruby core extensions used both by Rails itself and your application <br />
  • The glue; ties together framework libraries and 3rd party plugins <br />
  • Build an application through the life of an HTTP request <br />
  • - List 10 most recent posts, newest first <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • ...since for most of you this is your first time seeing Ruby code, let&#x2019;s look at this a little bit <br />
  • <br />
  • <br />
  • any instance variables in a controller are automatically handed into the view <br />
  • ...since for most of you this is your first time seeing Ruby code, let&#x2019;s look at this a little bit <br />
  • <br />
  • <br />
  • <br />
  • ActiveRecord is.... <br /> Default option, but you can use any ORM that implements ActiveModel <br />
  • <br />
  • <br />
  • <br />
  • Inheriting from ActiveRecord::Base does some pretty cool things for us <br />
  • Because I have a class called Post AR knows to look up... <br /> <br /> it also gives us some more time saving methods like... <br />
  • <br />
  • <br />
  • <br />
  • find_by_title will call SQL right away <br /> .where (and other query methods) will delegate the SQL call to the first time the array is used <br />
  • Way to go forward and backwards between versions of your database <br />
  • <br />
  • <br />
  • We didn&#x2019;t have to write a single line of data access code <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • &#x2026;here&#x2019;s some more strange Ruby syntax <br />
  • <br />
  • <br />
  • this helper method generates the html for a link <br />
  • this helper method generates the html for a link <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • &#x2026;this generates a number of helpful routes for us <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • ...since for most of you this is your first time seeing Ruby code, let&#x2019;s look at this a little bit <br />
  • params[:id] comes from resources route <br />
  • <br />
  • <br />
  • <br />
  • ActiveRecord is.... <br /> Default option, but you can use any ORM that implements ActiveModel <br />
  • We still haven&#x2019;t written a single line of data access code <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • &#x2026;here&#x2019;s some more strange Ruby syntax <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • &#x2026;this generates a number of helpful routes for us <br />
  • <br />
  • <br />
  • <br />
  • ...since for most of you this is your first time seeing Ruby code, let&#x2019;s look at this a little bit <br />
  • <br />
  • <br />
  • <br />
  • ActiveRecord is.... <br /> Default option, but you can use any ORM that implements ActiveModel <br />
  • We still haven&#x2019;t written a single line of data access code <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • With builder all of our block parameters become parent XML tags and all of our method calls child tags; we define attributes by passing a hash to a tag method <br /> <br /> &#x2026;what if we wanted to enable easy Javascript interaction? <br />
  • <br />
  • <br />
  • &#x2026;this generates a number of helpful routes for us <br />
  • <br />
  • <br />
  • <br />
  • ...since for most of you this is your first time seeing Ruby code, let&#x2019;s look at this a little bit <br />
  • <br />
  • <br />
  • <br />
  • ActiveRecord is.... <br /> Default option, but you can use any ORM that implements ActiveModel <br />
  • We still haven&#x2019;t written a single line of data access code <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • respond_with tells ActionController to format the object if it can <br /> <br /> Rails can convert any object into JSON <br />
  • <br />
  • We&#x2019;ve barely scratched the surface of what Rails can do. <br />
  • Convention is very powerful, but sometimes it makes sense to override the defaults <br />
  • Rails gets most of its flexibility from the Ruby language. Uses &#x201C;metaprogramming&#x201D; to generate code at runtime. Optimized for the best of productivity & performance. <br />
  • You&#x2019;d be surprised to see who&#x2019;s using Rails. <br />
  • Highly recommend some further reading to get a better feel for how you can make Rails work for you. <br />
  • <br />
  • <br />
  • <br />
  • ...in case you missed it <br />
  • <br />
  • <br />

An Introduction to Ruby on Rails An Introduction to Ruby on Rails Presentation Transcript

  • density!"! Ruby on Rails An Historical Introduction Cleveland Web Sig June 19, 2010
  • Overview
  • Joe Fiorini Rails Developer, Technology Evangelist, Husband, Dog Lover
  • density!"!
  • Goals Why to use Rails? What’s Ruby and what’s Rails? How does Rails make developers happy? Where do I go for more information?
  • Assumptions
  • Assumptions Basic HTTP knowledge
  • Assumptions Basic HTTP knowledge Basic object-oriented principles
  • Assumptions Basic HTTP knowledge Basic object-oriented principles Dynamic web development
  • Assumptions Basic HTTP knowledge Basic object-oriented principles Dynamic web development SQL
  • #websigrails For the Twits
  • Core Philosophy
  • DRY Don’t Repeat Yourself
  • Convention Over Configuration Get Started Faster!
  • REST Your Application as an API
  • MVC
  • Model Data Tier
  • View Displayed to the user
  • Controller Tying the model and view together
  • “ I'm trying to make Ruby natural, not simple. Yukihiro “Matz” Matsumoto
  • ActionPack ActiveModel ActionMailer ActiveResource ActiveSupport Railties
  • ActionPack ActiveModel ActionMailer ActiveResource ActiveSupport Railties
  • ActionPack ActiveModel ActionMailer ActiveResource ActiveSupport Railties
  • ActionPack ActiveModel ActionMailer ActiveResource ActiveSupport Railties
  • ActionPack ActiveModel ActionMailer ActiveResource ActiveSupport Railties
  • ActionPack ActiveModel ActionMailer ActiveResource ActiveSupport Railties
  • ActionPack ActiveModel ActionMailer ActiveResource ActiveSupport Railties
  • ActionPack ActiveModel ActionMailer ActiveResource ActiveSupport Railties
  • Life of a Request
  • http://www.densitypop.com/
  • ActionPack ActionDispatch
  • ActionPack Blog3::Application.routes.draw do |map| root :to => "posts#index" end
  • ActionPack ActionDispatch
  • ActionPack ActionDispatch
  • ActionPack ActionDispatch ActionController
  • ActionPack ActionDispatch class PostsController < ApplicationController def index @posts = Post.order("created_at DESC"). limit(10) end end
  • ActionPack ActionDispatch Inheritence class PostsController < ApplicationController def index @posts = Post.order("created_at DESC"). limit(10) end end
  • ActionPack ActionDispatch Instance Method class PostsController < ApplicationController def index @posts = Post.order("created_at DESC"). limit(10) end end
  • ActionPack ActionDispatch Instance Variable (field/private variable) class PostsController < ApplicationController def index @posts = Post.order("created_at DESC"). limit(10) end end
  • ActionPack ActionDispatch Class Class method (static) class PostsController < ApplicationController def index @posts = Post.order("created_at DESC"). limit(10) end end
  • ActionPack ActionDispatch ActionController
  • ActionPack ActionDispatch ActionController
  • ActiveModel ActionDispatch ActionController ActiveRecord
  • ActiveRecord SQLite/ MySQL/ PostgreSQL/…
  • ActiveRecord SQLite/ MySQL/ MongoDB/… posts id title body
  • ActiveRecord SQLite/ MySQL/ MongoDB/… posts id Post title body
  • ActiveRecord class Post < ActiveRecord::Base end
  • ActiveRecord post.title post.body post.id post.save post.destroy
  • ActiveRecord Post.find_by_title "Awesomest post ever!" SELECT * FROM posts WHERE title = 'Awesomest post ever!'
  • ActiveRecord Post.where("title = 'Awesomest post ever!'") SELECT * FROM posts WHERE title = 'Awesomest post ever!'
  • ActiveRecord Post.joins(:authors).where("authors.name = 'Joe'") SELECT * FROM posts INNER JOIN authors ON posts.author_id = authors.id WHERE authors.author_name = 'Joe'
  • ActiveRecord Post.find_by_title "Awesomest post ever!" vs. Post.where("title = 'Awesomest post ever!'")
  • ActiveRecord class CreatePosts < ActiveRecord::Migration def self.up create_table :posts do |t| t.string :title t.text :body t.timestamps end end def self.down drop_table :posts end end
  • ActiveRecord Validations validates_presence_of validates_uniqueness_of validates_format_of validates_length_of …
  • ActiveRecord http://guides.rails.info RTFM
  • ActiveModel ActionDispatch ActionController class Post < ActiveRecord::Base end
  • ActiveModel ActionDispatch ActionController ActiveRecord
  • ActiveModel ActionDispatch ActionController ActiveRecord
  • ActionPack ActionDispatch ActionController ActiveRecord ActionView
  • ActionPack ActionDispatch ActionController ActiveRecord <ol> <% @posts.each do |post| %> <li class="post"> <h2><%= link_to post.title, post %></h2> <span><%= post.body %></span> </li> <% end %> </ol>
  • ActionPack ActionDispatch Iterator (for loop) ActionController ActiveRecord <ol> <% @posts.each do |post| %> <li class="post"> <h2><%= link_to post.title, post %></h2> <span><%= post.body %></span> </li> <% end %> </ol>
  • ActionPack Block (anonymous function) ActionDispatch ActionController ActiveRecord Block parameter <ol> <% @posts.each do |post| %> do |post| %> <li class="post"> <h2><%= link_to post.title, post %></h2> <span><%= post.body %></span> </li> <% end %> <% end %> </ol>
  • ActionPack ActionDispatch ActionController ActiveRecord Helper method <ol> <% @posts.each do |post| %> <li class="post"> <h2> </h2> <span><%= post.body %></span> %> <%= link_to post.title, post </li> <% end %> </ol>
  • ActionPack ActionDispatch ActionController ActiveRecord Helper method <ol> <% @posts.each do |post| %> <li class="post"> <h2> </h2> <span><%= post.body %></span> %> <%= link_to post.title, post </li> <% end %> <a href="...">Post Title</a> </ol>
  • ActionPack ActionDispatch ActionController ActiveRecord ActionView
  • ActionPack ActionDispatch ActionController ActionView ActiveRecord <html> ... </html>
  • http://densitypop.com/posts/22
  • ActionPack ActionDispatch
  • ActionPack Blog3::Application.routes.draw do |map| resources :posts end
  • GET /posts/new Post#new
  • POST /posts Post#create
  • GET /posts/edit/22 Post#edit
  • PUT /post/22 Post#update
  • GET /posts/22 Post#show
  • DELETE /posts/22 Post#destroy
  • ActionPack ActionDispatch
  • ActionPack ActionDispatch
  • ActionPack ActionDispatch ActionController
  • ActionPack ActionDispatch class PostsController < ApplicationController def show @post = Post.find(params[:id]) end end
  • ActionPack ActionDispatch Request Parameter Hash class PostsController < ApplicationController def show @post = Post.find( ) end params[:id] end
  • ActionPack ActionDispatch ActionController
  • ActionPack ActionDispatch ActionController
  • ActiveModel ActionDispatch ActionController ActiveRecord
  • ActiveModel ActionDispatch ActionController class Post < ActiveRecord::Base end
  • ActiveModel ActionDispatch ActionController ActiveRecord
  • ActiveModel ActionDispatch ActionController ActiveRecord
  • ActionPack ActionDispatch ActionController ActiveRecord ActionView
  • ActionPack ActionDispatch ActionController ActiveRecord <h1><%= link_to @post.title, @post %></h1> <span><%= @post.body %></span>
  • ActionPack ActionDispatch ActionController ActiveRecord ActionView
  • ActionPack ActionDispatch ActionController ActionView ActiveRecord <html> ... </html>
  • http://densitypop.com/feed.xml
  • ActionPack ActionDispatch
  • ActionPack Blog3::Application.routes.draw do |map| match 'feed.xml', :to => 'posts#index' end
  • ActionPack ActionDispatch
  • ActionPack ActionDispatch
  • ActionPack ActionDispatch ActionController
  • ActionPack ActionDispatch class PostsController < ApplicationController respond_to :xml def index respond_with(@posts = Post. order("created_at DESC"). limit(10)) end end
  • ActionPack ActionDispatch ActionController
  • ActionPack ActionDispatch ActionController
  • ActiveModel ActionDispatch ActionController ActiveRecord
  • ActiveModel ActionDispatch ActionController class Post < ActiveRecord::Base end
  • ActiveModel ActionDispatch ActionController ActiveRecord
  • ActiveModel ActionDispatch ActionController ActiveRecord
  • ActionPack ActionDispatch ActionController ActiveRecord ActionView
  • ActionPack ActionDispatch ActionController ActiveRecord atom_feed do |feed| feed.title("Joe's Awesome Blog!") feed.updated(@posts.first.created_at) @posts.each do |post| feed.entry(post) do |entry| entry.title(post.title) entry.content(post.body, :type => 'html') entry.author { |author| author.name("Joe") } end end end
  • http://densitypop.com/posts.json
  • ActionPack ActionDispatch
  • ActionPack Blog3::Application.routes.draw do |map| resources :posts end
  • ActionPack ActionDispatch
  • ActionPack ActionDispatch
  • ActionPack ActionDispatch ActionController
  • ActionPack ActionDispatch class PostsController < ApplicationController respond_to :xml, :json def index respond_with(@posts = Post. order("created_at DESC"). limit(10)) end end
  • ActionPack ActionDispatch ActionController
  • ActionPack ActionDispatch ActionController
  • ActiveModel ActionDispatch ActionController ActiveRecord
  • ActiveModel ActionDispatch ActionController class Post < ActiveRecord::Base end
  • ActiveModel ActionDispatch ActionController ActiveRecord
  • ActiveModel ActionDispatch ActionController ActiveRecord
  • ActionPack ActionDispatch ActionController ActiveRecord ActionView
  • ActionPack ActionDispatch ActionController ActiveRecord [This slide intentionally left blank]
  • There you go. Isn’t that easy?
  • Digging Deeper
  • Nothing is Sacred Anything can be overridden
  • Not all magic Some illusions too
  • Enterprise Ready http://www.workingwithrails.com/high-profile-organisations
  • http://bit.ly/websigrailslinks
  • Resources http://bit.ly/websigrailslinks
  • Cleveland Ruby Brigade http://www.meetup.com/ClevelandRuby http://bit.ly/websigrailslinks
  • Agile Web Dev. with Rails http://pragprog.com/titles/rails4/ http://bit.ly/websigrailslinks
  • Rails 3 in Action http://www.manning.com/katz/ http://bit.ly/websigrailslinks
  • http://bit.ly/websigrailslinks
  • The End
  • http://speakerrate.com/joefiorini Please rate this talk (only if it’s good)!