際際滷

際際滷Share a Scribd company logo
Rails Kool-Aid
Giving you your very own
glass, drink up!
Saturday, November 20, 2010
Me llamo Ryan Abbott
Co-founder of Loudpixel Inc.
Developing web sites/apps for nearly 10
years #angel鍖recounts
Largest production Rails application is
Levee #itsawesome
Ten-ish other production apps
HI, WHO ARE YOU AGAIN?
Saturday, November 20, 2010
WHO/WHAT IS RUBY ON RAILS?
Web Framework built on top of Ruby
Created by David Heinemeier Hansson
DHH released Rails as open source in July
of 2004 but was the sole contributor
Rails 1.0 was released on December 13,
2005
Rails 3.0 (current) was released on
August 29, 2010 - it has 1700+
contributors
Saturday, November 20, 2010
WHY RAILS?
Rapid Application Development
Defaults - Scaffold, relationships,
nested objects, etc.
Plugins!
Deployment
Sites like Heroku provide free hosting,
and all you need is GIT
Community
1700+ contributors and tens of thousands
of live apps
Saturday, November 20, 2010
LITTLE BIG WORDS
CRUD (Create, Read, Update, Delete)
The 4 basic functions performed on the
data that our application stores
MVC (Model-View-Controller)
The architecture pattern used by rails
DRY (Dont Repeat Yourself)
Software development principle
emphasized within the rails community
REST (Representative State Transfer)
Using identi鍖ers to represent resources
Saturday, November 20, 2010
MODEL-VIEW-CONTROLLER
Models
Manages how the data is stored, and how
that data behaves
Views
Renders the models in a way best suited
for the requested format
Controllers
Receives instructions from users based
on actions, and informs the models how
they should respond and the views what
they should display
Saturday, November 20, 2010
REST[ful] RESOURCES
RESTful URLs provide a human readable
set of resources, and their states.
An example could be
/users/15/edit
What do we expect here?
User
Id of 15
Edit view to be displayed
Saturday, November 20, 2010
CREATING A RAILS PROJECT
> rails new blogpress
Creates a new directory called blogpress
containing the following:
Gem鍖le
Home to your GEM dependencies
app
This is where youll 鍖nd your models,
views, and controllers
con鍖g
As you would imagine, here lives your
con鍖gurations; routes, etc.
Saturday, November 20, 2010
DIRECTORY BREAKDOWN CONT
db
Contains your database schema and
migrations
log
Development, Test, and Production logs
public
Web accessible directory, images,
stylesheets, javascript, etc.
vendor
A centralized location for third-party
code from plugins to gem source
Saturday, November 20, 2010
APPLICATION READY, NEXT?
> bundle install
Bundler is a tool that installs required
gems for your application. Bundler is
able to determine dependencies and
children without instructions from you
database con鍖guration (database.yml)
Defaults to sqlite, allows for MySQL,
and PostgreSQL OOB, and others with
use of plugins
development, test, production
Saturday, November 20, 2010
DATABASE CONFIGURED, SO...
> rake db:create
This will read the database.yml 鍖le
and create the databases requested
rake, WTF?
Rake is a way to run tasks, the
majority of tasks you run are already
provided by Rails, but you can always
create your own
> rake -T
Display a list of all rake tasks
available
Saturday, November 20, 2010
HELLO, WORLD? RAILS?
> rails server
Starts the rails server at port 3000 and
allows us to navigate our new site!
Check things out, in the browser view:
http://127.0.0.1:3000/
Saturday, November 20, 2010
Saturday, November 20, 2010
Saturday, November 20, 2010
DATABASE CONFIGURED, SO...
> rm public/index.html
We dont want this page displaying
when visitors come to our blog
> rails generate controller home index
Generate a controller with only an
index action to take the place of
public/index.html
Update con鍖g/routes.rb to let the app
know that our root should be
REMOVE get "home/index"
ADD root :to => home#index
Saturday, November 20, 2010
GOODBYE DEFAULT
Saturday, November 20, 2010
WHAT MAKES UP A BLOG?
Saturday, November 20, 2010
EVERY BLOG HAS POSTS
> rails generate scaffold Post
author:string title:string content:text
permalink:text
Scaffold creates full CRUD
functionality for us, including our
model, view, controller, and even our
database migration
rake db:migrate
Calls our self.up method to create the
posts database table
Saturday, November 20, 2010
OH POSTS, WHERE ART THOU?
In the browser, lets have a look at:
http://127.0.0.1:3000/posts
Saturday, November 20, 2010
WHATS MISSING?
Posts
Comments (haters gone hate)
Tags / Keywords (Im here for ONE thing)
Validation (plan for the spoon in the knife drawer)
Overall Blog
Authentication (hackers gone hack)
Most Recent Posts (laziness is contagious)
Saturday, November 20, 2010
COMMENTS
> rails generate scaffold Comment
post:references email:string
content:text
> rake db:migrate
con鍖g/routes.rb
1307656, 1307661
Saturday, November 20, 2010
ROUTING FOR COMMENTS
/comments
/comments/1
/comments/1/edit
/posts
/posts/1
/posts/1/edit
/posts/1/comments
/posts/1/comments/1
/posts/1/comments/edit
/comments?post_id=1
/comments/1?post_id=1
/comments/1/edit?post_id=1
@post = Post.
鍖nd(params[:post_id])
@comments = @post.comments
1307656, 1307661
Saturday, November 20, 2010
COMMENTS
<h2>Comments</h2>
<% @post.comments.each do |comment| %>
<p>
<b><%= comment.email %></b>
<%= comment.content %>
</p>
<% end %>
<h2>Add a comment:</h2>
<%= form_for([@post, @post.comments.build]) do |f| %>
<% if @comment && @comment.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@comment.errors.count, "error") %> prohibited this comment from being saved:</h2>
<ul>
<% @comment.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="鍖eld">
<%= f.label :email %><br />
<%= f.text_鍖eld :email %>
</div>
<div class="鍖eld">
<%= f.label :content %><br />
<%= f.text_area :content %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
app/views/posts/show.html.erb
@post = Post.鍖nd(params[:post_id])
@comment = @post.comments.new(params[:comment])
respond_to do |format|
if @comment.save
format.html { redirect_to(post_path(@post), :notice => 'Comment was successfully
created.') }
format.xml { render :xml => @post, :status => :created, :location => post_path(@post) }
else
format.html { redirect_to post_path(@post) }
format.xml { render :xml => @comment.errors, :status => :unprocessable_entity }
end
end
app/views/controllers/comments_controller.rb
has_many :comments
app/models/post.rb
Saturday, November 20, 2010
SHOWING COMMENTS
1307643
Saturday, November 20, 2010
ACCEPTING COMMENTS
1314025
Saturday, November 20, 2010
BRING ON THE SPAM!
Saturday, November 20, 2010
TAGS / KEYWORDS
gem 'acts-as-taggable-on'
> bundle install
> rails generate acts_as_taggable_on:migration
> rake db:migrate
acts_as_taggable
1307777
Saturday, November 20, 2010
VALIDATION OPTIONS
:presence => true
:uniqueness => true
:numericality => true
:length => { :minimum => 0, maximum => 2000 }
:format => { :with => /.*/ }
:inclusion => { :in => [1,2,3] }
:exclusion => { :in => [1,2,3] }
:acceptance => true
:con鍖rmation => true
Saturday, November 20, 2010
VALIDATION
Comment Validation
Post Validation
1307783, 1307789
Saturday, November 20, 2010
AUTHENTICATION
Basic HTTP authentication prompts users
via a browser popup. This authentication
lasts until the browser is closed.
1307757
Saturday, November 20, 2010
MOST RECENT POSTS
1309253
We want to display the top n posts on the main page,
of course well want the n more recent posts
Saturday, November 20, 2010
JOBS, GIGS, CAREERS
http://jobs.37signals.com/
http://toprubyjobs.com/
http://jobs.rubynow.com/
http://www.railsjob.com/
http://railswork.com/
http://weblog.rubyonrails.org/jobs
http://www.rorjobs.com/
http://www.railslodge.com/jobs
http://ruby.jobmotel.com/
Saturday, November 20, 2010
HOSTING, DEPLOYMENT
http://heroku.com/
http://engineyard.com/
http://www.webbynode.com/
http://www.rubyenterpriseedition.com/
https://github.com/
Saturday, November 20, 2010
ONLINE RESOURCES?
http://tryruby.org/
A 15 minute, in-browser, tutorial showing you the
basics of Ruby
http://railsforzombies.org/
Online interactive tutorials that teach you rails
right in the browser
http://rubyonrails.org/screencasts/rails3
A set of beautiful screencasts by Gregg Pollack that
walk viewers though the details of the Rails core
pieces
http://railscasts.com/
Extremely helpful videos from Ryan Bates - started
back in 2007 Ryan is always on top of new plugins
and methods of doing things
Saturday, November 20, 2010
Rails Kool-Aid
Ryan Abbott
@MSURabbott
ryan@loudpixel.com
Saturday, November 20, 2010
Rails Kool-Aid
Ryan Abbott
@MSURabbott
ryan@loudpixel.com
http://spkr8.com/t/5139
http://slidesha.re/b09DCa
Saturday, November 20, 2010

More Related Content

Similar to Ruby on-rails-workshop (20)

PDF
Ruby On Rails Starter Kit
El Orabi Mohamed Ikbal
PPT
Ruby on Rails introduction
Tran Hung
PDF
Ruby Rails Web Development
Sonia Simi
PDF
Rails 4.0
Robert Gogolok
KEY
Supa fast Ruby + Rails
Jean-Baptiste Feldis
PPT
Rail3 intro 29th_sep_surendran
SPRITLE SOFTWARE PRIVATE LIMIT ED
PDF
Lecture #5 Introduction to rails
Evgeniy Hinyuk
PDF
Introduction to Rails by Evgeniy Hinyuk
Pivorak MeetUp
PPTX
Intro to Rails Give Camp Atlanta
Jason Noble
PPTX
Ruby on rails3 - introduction to rails
Emad Elsaid
PPT
Rails 101
The Active Network
PPT
Introduction to Ruby on Rails
Manoj Kumar
KEY
UPenn on Rails intro
Mat Schaffer
PDF
RoR (Ruby on Rails)
scandiweb
PDF
Ruby On Rails Basics
Amit Solanki
PDF
Curso rails
Icalia Labs
PPT
Ruby On Rails Siddhesh
Siddhesh Bhobe
PPTX
Learning to code for startup mvp session 3
Henry S
PDF
Rails 3 : Cool New Things
Y. Thong Kuah
PDF
Frozen Rails 際際滷s
carllerche
Ruby On Rails Starter Kit
El Orabi Mohamed Ikbal
Ruby on Rails introduction
Tran Hung
Ruby Rails Web Development
Sonia Simi
Rails 4.0
Robert Gogolok
Supa fast Ruby + Rails
Jean-Baptiste Feldis
Rail3 intro 29th_sep_surendran
SPRITLE SOFTWARE PRIVATE LIMIT ED
Lecture #5 Introduction to rails
Evgeniy Hinyuk
Introduction to Rails by Evgeniy Hinyuk
Pivorak MeetUp
Intro to Rails Give Camp Atlanta
Jason Noble
Ruby on rails3 - introduction to rails
Emad Elsaid
Introduction to Ruby on Rails
Manoj Kumar
UPenn on Rails intro
Mat Schaffer
RoR (Ruby on Rails)
scandiweb
Ruby On Rails Basics
Amit Solanki
Curso rails
Icalia Labs
Ruby On Rails Siddhesh
Siddhesh Bhobe
Learning to code for startup mvp session 3
Henry S
Rails 3 : Cool New Things
Y. Thong Kuah
Frozen Rails 際際滷s
carllerche

Recently uploaded (20)

PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
PDF
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
DOCX
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
PDF
How to Visualize the Spatio-Temporal Data Using CesiumJS
SANGHEE SHIN
PDF
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
PDF
Python Conference Singapore - 19 Jun 2025
ninefyi
PPTX
Simplifica la seguridad en la nube y la detecci坦n de amenazas con FortiCNAPP
Cristian Garcia G.
PDF
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
PDF
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
PDF
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
PDF
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
ScyllaDB
PDF
Scaling i.MX Applications Processors Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
PPTX
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
PPTX
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
PPTX
叶Wondershare Filmora Crack 14.0.7 + Key Download 2025
sebastian aliya
PDF
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
PDF
MPU+: A Transformative Solution for Next-Gen AI at the Edge, a Presentation...
Edge AI and Vision Alliance
PDF
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
PDF
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
PDF
Plugging AI into everything: Model Context Protocol Simplified.pdf
Abati Adewale
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
How to Visualize the Spatio-Temporal Data Using CesiumJS
SANGHEE SHIN
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
Python Conference Singapore - 19 Jun 2025
ninefyi
Simplifica la seguridad en la nube y la detecci坦n de amenazas con FortiCNAPP
Cristian Garcia G.
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
ScyllaDB
Scaling i.MX Applications Processors Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
叶Wondershare Filmora Crack 14.0.7 + Key Download 2025
sebastian aliya
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
MPU+: A Transformative Solution for Next-Gen AI at the Edge, a Presentation...
Edge AI and Vision Alliance
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
Plugging AI into everything: Model Context Protocol Simplified.pdf
Abati Adewale
Ad

Ruby on-rails-workshop

  • 1. Rails Kool-Aid Giving you your very own glass, drink up! Saturday, November 20, 2010
  • 2. Me llamo Ryan Abbott Co-founder of Loudpixel Inc. Developing web sites/apps for nearly 10 years #angel鍖recounts Largest production Rails application is Levee #itsawesome Ten-ish other production apps HI, WHO ARE YOU AGAIN? Saturday, November 20, 2010
  • 3. WHO/WHAT IS RUBY ON RAILS? Web Framework built on top of Ruby Created by David Heinemeier Hansson DHH released Rails as open source in July of 2004 but was the sole contributor Rails 1.0 was released on December 13, 2005 Rails 3.0 (current) was released on August 29, 2010 - it has 1700+ contributors Saturday, November 20, 2010
  • 4. WHY RAILS? Rapid Application Development Defaults - Scaffold, relationships, nested objects, etc. Plugins! Deployment Sites like Heroku provide free hosting, and all you need is GIT Community 1700+ contributors and tens of thousands of live apps Saturday, November 20, 2010
  • 5. LITTLE BIG WORDS CRUD (Create, Read, Update, Delete) The 4 basic functions performed on the data that our application stores MVC (Model-View-Controller) The architecture pattern used by rails DRY (Dont Repeat Yourself) Software development principle emphasized within the rails community REST (Representative State Transfer) Using identi鍖ers to represent resources Saturday, November 20, 2010
  • 6. MODEL-VIEW-CONTROLLER Models Manages how the data is stored, and how that data behaves Views Renders the models in a way best suited for the requested format Controllers Receives instructions from users based on actions, and informs the models how they should respond and the views what they should display Saturday, November 20, 2010
  • 7. REST[ful] RESOURCES RESTful URLs provide a human readable set of resources, and their states. An example could be /users/15/edit What do we expect here? User Id of 15 Edit view to be displayed Saturday, November 20, 2010
  • 8. CREATING A RAILS PROJECT > rails new blogpress Creates a new directory called blogpress containing the following: Gem鍖le Home to your GEM dependencies app This is where youll 鍖nd your models, views, and controllers con鍖g As you would imagine, here lives your con鍖gurations; routes, etc. Saturday, November 20, 2010
  • 9. DIRECTORY BREAKDOWN CONT db Contains your database schema and migrations log Development, Test, and Production logs public Web accessible directory, images, stylesheets, javascript, etc. vendor A centralized location for third-party code from plugins to gem source Saturday, November 20, 2010
  • 10. APPLICATION READY, NEXT? > bundle install Bundler is a tool that installs required gems for your application. Bundler is able to determine dependencies and children without instructions from you database con鍖guration (database.yml) Defaults to sqlite, allows for MySQL, and PostgreSQL OOB, and others with use of plugins development, test, production Saturday, November 20, 2010
  • 11. DATABASE CONFIGURED, SO... > rake db:create This will read the database.yml 鍖le and create the databases requested rake, WTF? Rake is a way to run tasks, the majority of tasks you run are already provided by Rails, but you can always create your own > rake -T Display a list of all rake tasks available Saturday, November 20, 2010
  • 12. HELLO, WORLD? RAILS? > rails server Starts the rails server at port 3000 and allows us to navigate our new site! Check things out, in the browser view: http://127.0.0.1:3000/ Saturday, November 20, 2010
  • 15. DATABASE CONFIGURED, SO... > rm public/index.html We dont want this page displaying when visitors come to our blog > rails generate controller home index Generate a controller with only an index action to take the place of public/index.html Update con鍖g/routes.rb to let the app know that our root should be REMOVE get "home/index" ADD root :to => home#index Saturday, November 20, 2010
  • 17. WHAT MAKES UP A BLOG? Saturday, November 20, 2010
  • 18. EVERY BLOG HAS POSTS > rails generate scaffold Post author:string title:string content:text permalink:text Scaffold creates full CRUD functionality for us, including our model, view, controller, and even our database migration rake db:migrate Calls our self.up method to create the posts database table Saturday, November 20, 2010
  • 19. OH POSTS, WHERE ART THOU? In the browser, lets have a look at: http://127.0.0.1:3000/posts Saturday, November 20, 2010
  • 20. WHATS MISSING? Posts Comments (haters gone hate) Tags / Keywords (Im here for ONE thing) Validation (plan for the spoon in the knife drawer) Overall Blog Authentication (hackers gone hack) Most Recent Posts (laziness is contagious) Saturday, November 20, 2010
  • 21. COMMENTS > rails generate scaffold Comment post:references email:string content:text > rake db:migrate con鍖g/routes.rb 1307656, 1307661 Saturday, November 20, 2010
  • 23. COMMENTS <h2>Comments</h2> <% @post.comments.each do |comment| %> <p> <b><%= comment.email %></b> <%= comment.content %> </p> <% end %> <h2>Add a comment:</h2> <%= form_for([@post, @post.comments.build]) do |f| %> <% if @comment && @comment.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@comment.errors.count, "error") %> prohibited this comment from being saved:</h2> <ul> <% @comment.errors.full_messages.each do |msg| %> <li><%= msg %></li> <% end %> </ul> </div> <% end %> <div class="鍖eld"> <%= f.label :email %><br /> <%= f.text_鍖eld :email %> </div> <div class="鍖eld"> <%= f.label :content %><br /> <%= f.text_area :content %> </div> <div class="actions"> <%= f.submit %> </div> <% end %> app/views/posts/show.html.erb @post = Post.鍖nd(params[:post_id]) @comment = @post.comments.new(params[:comment]) respond_to do |format| if @comment.save format.html { redirect_to(post_path(@post), :notice => 'Comment was successfully created.') } format.xml { render :xml => @post, :status => :created, :location => post_path(@post) } else format.html { redirect_to post_path(@post) } format.xml { render :xml => @comment.errors, :status => :unprocessable_entity } end end app/views/controllers/comments_controller.rb has_many :comments app/models/post.rb Saturday, November 20, 2010
  • 26. BRING ON THE SPAM! Saturday, November 20, 2010
  • 27. TAGS / KEYWORDS gem 'acts-as-taggable-on' > bundle install > rails generate acts_as_taggable_on:migration > rake db:migrate acts_as_taggable 1307777 Saturday, November 20, 2010
  • 28. VALIDATION OPTIONS :presence => true :uniqueness => true :numericality => true :length => { :minimum => 0, maximum => 2000 } :format => { :with => /.*/ } :inclusion => { :in => [1,2,3] } :exclusion => { :in => [1,2,3] } :acceptance => true :con鍖rmation => true Saturday, November 20, 2010
  • 29. VALIDATION Comment Validation Post Validation 1307783, 1307789 Saturday, November 20, 2010
  • 30. AUTHENTICATION Basic HTTP authentication prompts users via a browser popup. This authentication lasts until the browser is closed. 1307757 Saturday, November 20, 2010
  • 31. MOST RECENT POSTS 1309253 We want to display the top n posts on the main page, of course well want the n more recent posts Saturday, November 20, 2010
  • 34. ONLINE RESOURCES? http://tryruby.org/ A 15 minute, in-browser, tutorial showing you the basics of Ruby http://railsforzombies.org/ Online interactive tutorials that teach you rails right in the browser http://rubyonrails.org/screencasts/rails3 A set of beautiful screencasts by Gregg Pollack that walk viewers though the details of the Rails core pieces http://railscasts.com/ Extremely helpful videos from Ryan Bates - started back in 2007 Ryan is always on top of new plugins and methods of doing things Saturday, November 20, 2010

Editor's Notes

  • #4: - Released Ruby on Rails as open source in July 2004, but did not share commit rights to the project until February 2005.
  • #5: - Released Ruby on Rails as open source in July 2004, but did not share commit rights to the project until February 2005.
  • #6: - Released Ruby on Rails as open source in July 2004, but did not share commit rights to the project until February 2005.
  • #7: - Released Ruby on Rails as open source in July 2004, but did not share commit rights to the project until February 2005.
  • #8: - Released Ruby on Rails as open source in July 2004, but did not share commit rights to the project until February 2005.