SlideShare ist ein Scribd-Unternehmen logo
1 von 36
Downloaden Sie, um offline zu lesen
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 #angelfirecounts
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 (Don’t Repeat Yourself)
Software development principle
emphasized within the rails community
REST (Representative State Transfer)
Using identifiers 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:
Gemfile
Home to your GEM dependencies
app
This is where you’ll find your models,
views, and controllers
config
As you would imagine, here lives your
configurations; routes, etc.
Saturday, November 20, 2010
DIRECTORY BREAKDOWN CON’T
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 configuration (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 file
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 don’t 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 config/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
WHAT’S MISSING?
Posts
Comments (haters gone hate)
Tags / Keywords (I’m 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
config/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.
find(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="field">
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label :content %><br />
<%= f.text_area :content %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
app/views/posts/show.html.erb
@post = Post.find(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
:confirmation => 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 we’ll 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

Más contenido relacionado

Ähnlich wie Ruby on-rails-workshop

Introduction to Node.js: perspectives from a Drupal dev
Introduction to Node.js: perspectives from a Drupal devIntroduction to Node.js: perspectives from a Drupal dev
Introduction to Node.js: perspectives from a Drupal devmcantelon
 
Newer Yankee Workshop - NoSQL
Newer Yankee Workshop -  NoSQLNewer Yankee Workshop -  NoSQL
Newer Yankee Workshop - NoSQLBrian Kaney
 
MacRuby & RubyMotion - Madridrb May 2012
MacRuby & RubyMotion - Madridrb May 2012MacRuby & RubyMotion - Madridrb May 2012
MacRuby & RubyMotion - Madridrb May 2012Mark Villacampa
 
Intro to Rails and MVC
Intro to Rails and MVCIntro to Rails and MVC
Intro to Rails and MVCSarah Allen
 
Intro to Rails Give Camp Atlanta
Intro to Rails Give Camp AtlantaIntro to Rails Give Camp Atlanta
Intro to Rails Give Camp AtlantaJason Noble
 
Using Ruby in Android Development
Using Ruby in Android DevelopmentUsing Ruby in Android Development
Using Ruby in Android DevelopmentAdam Blum
 
Javascript Frameworks Comparison
Javascript Frameworks ComparisonJavascript Frameworks Comparison
Javascript Frameworks ComparisonDeepu S Nath
 
Building Dojo in the Cloud
Building Dojo in the CloudBuilding Dojo in the Cloud
Building Dojo in the CloudJames Thomas
 
Angularjs Tutorial for Beginners
Angularjs Tutorial for BeginnersAngularjs Tutorial for Beginners
Angularjs Tutorial for Beginnersrajkamaltibacademy
 
Kotlin. One language to dominate them all.
Kotlin. One language to dominate them all.Kotlin. One language to dominate them all.
Kotlin. One language to dominate them all.Daniel Llanos Muñoz
 
Making your site mobile-friendly - Standards-Next 12.06.2010
Making your site mobile-friendly - Standards-Next 12.06.2010Making your site mobile-friendly - Standards-Next 12.06.2010
Making your site mobile-friendly - Standards-Next 12.06.2010Patrick Lauke
 
Tek 2013 - Building Web Apps from a New Angle with AngularJS
Tek 2013 - Building Web Apps from a New Angle with AngularJSTek 2013 - Building Web Apps from a New Angle with AngularJS
Tek 2013 - Building Web Apps from a New Angle with AngularJSPablo Godel
 
Making your site mobile-friendly / RIT++
Making your site mobile-friendly / RIT++Making your site mobile-friendly / RIT++
Making your site mobile-friendly / RIT++Patrick Lauke
 
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and BackboneJavascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and BackboneDeepu S Nath
 
Create rails project
Create rails projectCreate rails project
Create rails projectAlain Bindele
 
JavaScript Presentation Frameworks and Libraries
JavaScript Presentation Frameworks and LibrariesJavaScript Presentation Frameworks and Libraries
JavaScript Presentation Frameworks and LibrariesOleksii Prohonnyi
 

Ähnlich wie Ruby on-rails-workshop (20)

Introduction to Node.js: perspectives from a Drupal dev
Introduction to Node.js: perspectives from a Drupal devIntroduction to Node.js: perspectives from a Drupal dev
Introduction to Node.js: perspectives from a Drupal dev
 
HTML5 Intro
HTML5 IntroHTML5 Intro
HTML5 Intro
 
Newer Yankee Workshop - NoSQL
Newer Yankee Workshop -  NoSQLNewer Yankee Workshop -  NoSQL
Newer Yankee Workshop - NoSQL
 
MacRuby & RubyMotion - Madridrb May 2012
MacRuby & RubyMotion - Madridrb May 2012MacRuby & RubyMotion - Madridrb May 2012
MacRuby & RubyMotion - Madridrb May 2012
 
Intro to Rails and MVC
Intro to Rails and MVCIntro to Rails and MVC
Intro to Rails and MVC
 
Rails 101
Rails 101Rails 101
Rails 101
 
Intro to Rails Give Camp Atlanta
Intro to Rails Give Camp AtlantaIntro to Rails Give Camp Atlanta
Intro to Rails Give Camp Atlanta
 
Using Ruby in Android Development
Using Ruby in Android DevelopmentUsing Ruby in Android Development
Using Ruby in Android Development
 
Javascript Frameworks Comparison
Javascript Frameworks ComparisonJavascript Frameworks Comparison
Javascript Frameworks Comparison
 
Building Dojo in the Cloud
Building Dojo in the CloudBuilding Dojo in the Cloud
Building Dojo in the Cloud
 
Road to Rails
Road to RailsRoad to Rails
Road to Rails
 
Angularjs Tutorial for Beginners
Angularjs Tutorial for BeginnersAngularjs Tutorial for Beginners
Angularjs Tutorial for Beginners
 
Kotlin. One language to dominate them all.
Kotlin. One language to dominate them all.Kotlin. One language to dominate them all.
Kotlin. One language to dominate them all.
 
Making your site mobile-friendly - Standards-Next 12.06.2010
Making your site mobile-friendly - Standards-Next 12.06.2010Making your site mobile-friendly - Standards-Next 12.06.2010
Making your site mobile-friendly - Standards-Next 12.06.2010
 
Tek 2013 - Building Web Apps from a New Angle with AngularJS
Tek 2013 - Building Web Apps from a New Angle with AngularJSTek 2013 - Building Web Apps from a New Angle with AngularJS
Tek 2013 - Building Web Apps from a New Angle with AngularJS
 
Making your site mobile-friendly / RIT++
Making your site mobile-friendly / RIT++Making your site mobile-friendly / RIT++
Making your site mobile-friendly / RIT++
 
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and BackboneJavascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
 
Kotlin - A language to dominate them all
Kotlin - A language to dominate them allKotlin - A language to dominate them all
Kotlin - A language to dominate them all
 
Create rails project
Create rails projectCreate rails project
Create rails project
 
JavaScript Presentation Frameworks and Libraries
JavaScript Presentation Frameworks and LibrariesJavaScript Presentation Frameworks and Libraries
JavaScript Presentation Frameworks and Libraries
 

Último

My key hands-on projects in Quantum, and QAI
My key hands-on projects in Quantum, and QAIMy key hands-on projects in Quantum, and QAI
My key hands-on projects in Quantum, and QAIVijayananda Mohire
 
TrustArc Webinar - How to Live in a Post Third-Party Cookie World
TrustArc Webinar - How to Live in a Post Third-Party Cookie WorldTrustArc Webinar - How to Live in a Post Third-Party Cookie World
TrustArc Webinar - How to Live in a Post Third-Party Cookie WorldTrustArc
 
UiPath Studio Web workshop series - Day 4
UiPath Studio Web workshop series - Day 4UiPath Studio Web workshop series - Day 4
UiPath Studio Web workshop series - Day 4DianaGray10
 
.NET 8 ChatBot with Azure OpenAI Services.pptx
.NET 8 ChatBot with Azure OpenAI Services.pptx.NET 8 ChatBot with Azure OpenAI Services.pptx
.NET 8 ChatBot with Azure OpenAI Services.pptxHansamali Gamage
 
Trailblazer Community - Flows Workshop (Session 2)
Trailblazer Community - Flows Workshop (Session 2)Trailblazer Community - Flows Workshop (Session 2)
Trailblazer Community - Flows Workshop (Session 2)Muhammad Tiham Siddiqui
 
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedInOutage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedInThousandEyes
 
CyberSecurity - Computers In Libraries 2024
CyberSecurity - Computers In Libraries 2024CyberSecurity - Computers In Libraries 2024
CyberSecurity - Computers In Libraries 2024Brian Pichman
 
IT Service Management (ITSM) Best Practices for Advanced Computing
IT Service Management (ITSM) Best Practices for Advanced ComputingIT Service Management (ITSM) Best Practices for Advanced Computing
IT Service Management (ITSM) Best Practices for Advanced ComputingMAGNIntelligence
 
Novo Nordisk's journey in developing an open-source application on Neo4j
Novo Nordisk's journey in developing an open-source application on Neo4jNovo Nordisk's journey in developing an open-source application on Neo4j
Novo Nordisk's journey in developing an open-source application on Neo4jNeo4j
 
Planetek Italia Srl - Corporate Profile Brochure
Planetek Italia Srl - Corporate Profile BrochurePlanetek Italia Srl - Corporate Profile Brochure
Planetek Italia Srl - Corporate Profile BrochurePlanetek Italia Srl
 
From the origin to the future of Open Source model and business
From the origin to the future of  Open Source model and businessFrom the origin to the future of  Open Source model and business
From the origin to the future of Open Source model and businessFrancesco Corti
 
2024.03.12 Cost drivers of cultivated meat production.pdf
2024.03.12 Cost drivers of cultivated meat production.pdf2024.03.12 Cost drivers of cultivated meat production.pdf
2024.03.12 Cost drivers of cultivated meat production.pdfThe Good Food Institute
 
Introduction to RAG (Retrieval Augmented Generation) and its application
Introduction to RAG (Retrieval Augmented Generation) and its applicationIntroduction to RAG (Retrieval Augmented Generation) and its application
Introduction to RAG (Retrieval Augmented Generation) and its applicationKnoldus Inc.
 
Emil Eifrem at GraphSummit Copenhagen 2024 - The Art of the Possible.pptx
Emil Eifrem at GraphSummit Copenhagen 2024 - The Art of the Possible.pptxEmil Eifrem at GraphSummit Copenhagen 2024 - The Art of the Possible.pptx
Emil Eifrem at GraphSummit Copenhagen 2024 - The Art of the Possible.pptxNeo4j
 
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptxGraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptxNeo4j
 
Extra-120324-Visite-Entreprise-icare.pdf
Extra-120324-Visite-Entreprise-icare.pdfExtra-120324-Visite-Entreprise-icare.pdf
Extra-120324-Visite-Entreprise-icare.pdfInfopole1
 
3 Pitfalls Everyone Should Avoid with Cloud Data
3 Pitfalls Everyone Should Avoid with Cloud Data3 Pitfalls Everyone Should Avoid with Cloud Data
3 Pitfalls Everyone Should Avoid with Cloud DataEric D. Schabell
 
The New Cloud World Order Is FinOps (Slideshow)
The New Cloud World Order Is FinOps (Slideshow)The New Cloud World Order Is FinOps (Slideshow)
The New Cloud World Order Is FinOps (Slideshow)codyslingerland1
 
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdfQ4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdfTejal81
 
EMEA What is ThousandEyes? Webinar
EMEA What is ThousandEyes? WebinarEMEA What is ThousandEyes? Webinar
EMEA What is ThousandEyes? WebinarThousandEyes
 

Último (20)

My key hands-on projects in Quantum, and QAI
My key hands-on projects in Quantum, and QAIMy key hands-on projects in Quantum, and QAI
My key hands-on projects in Quantum, and QAI
 
TrustArc Webinar - How to Live in a Post Third-Party Cookie World
TrustArc Webinar - How to Live in a Post Third-Party Cookie WorldTrustArc Webinar - How to Live in a Post Third-Party Cookie World
TrustArc Webinar - How to Live in a Post Third-Party Cookie World
 
UiPath Studio Web workshop series - Day 4
UiPath Studio Web workshop series - Day 4UiPath Studio Web workshop series - Day 4
UiPath Studio Web workshop series - Day 4
 
.NET 8 ChatBot with Azure OpenAI Services.pptx
.NET 8 ChatBot with Azure OpenAI Services.pptx.NET 8 ChatBot with Azure OpenAI Services.pptx
.NET 8 ChatBot with Azure OpenAI Services.pptx
 
Trailblazer Community - Flows Workshop (Session 2)
Trailblazer Community - Flows Workshop (Session 2)Trailblazer Community - Flows Workshop (Session 2)
Trailblazer Community - Flows Workshop (Session 2)
 
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedInOutage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
 
CyberSecurity - Computers In Libraries 2024
CyberSecurity - Computers In Libraries 2024CyberSecurity - Computers In Libraries 2024
CyberSecurity - Computers In Libraries 2024
 
IT Service Management (ITSM) Best Practices for Advanced Computing
IT Service Management (ITSM) Best Practices for Advanced ComputingIT Service Management (ITSM) Best Practices for Advanced Computing
IT Service Management (ITSM) Best Practices for Advanced Computing
 
Novo Nordisk's journey in developing an open-source application on Neo4j
Novo Nordisk's journey in developing an open-source application on Neo4jNovo Nordisk's journey in developing an open-source application on Neo4j
Novo Nordisk's journey in developing an open-source application on Neo4j
 
Planetek Italia Srl - Corporate Profile Brochure
Planetek Italia Srl - Corporate Profile BrochurePlanetek Italia Srl - Corporate Profile Brochure
Planetek Italia Srl - Corporate Profile Brochure
 
From the origin to the future of Open Source model and business
From the origin to the future of  Open Source model and businessFrom the origin to the future of  Open Source model and business
From the origin to the future of Open Source model and business
 
2024.03.12 Cost drivers of cultivated meat production.pdf
2024.03.12 Cost drivers of cultivated meat production.pdf2024.03.12 Cost drivers of cultivated meat production.pdf
2024.03.12 Cost drivers of cultivated meat production.pdf
 
Introduction to RAG (Retrieval Augmented Generation) and its application
Introduction to RAG (Retrieval Augmented Generation) and its applicationIntroduction to RAG (Retrieval Augmented Generation) and its application
Introduction to RAG (Retrieval Augmented Generation) and its application
 
Emil Eifrem at GraphSummit Copenhagen 2024 - The Art of the Possible.pptx
Emil Eifrem at GraphSummit Copenhagen 2024 - The Art of the Possible.pptxEmil Eifrem at GraphSummit Copenhagen 2024 - The Art of the Possible.pptx
Emil Eifrem at GraphSummit Copenhagen 2024 - The Art of the Possible.pptx
 
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptxGraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
GraphSummit Copenhagen 2024 - Neo4j Vision and Roadmap.pptx
 
Extra-120324-Visite-Entreprise-icare.pdf
Extra-120324-Visite-Entreprise-icare.pdfExtra-120324-Visite-Entreprise-icare.pdf
Extra-120324-Visite-Entreprise-icare.pdf
 
3 Pitfalls Everyone Should Avoid with Cloud Data
3 Pitfalls Everyone Should Avoid with Cloud Data3 Pitfalls Everyone Should Avoid with Cloud Data
3 Pitfalls Everyone Should Avoid with Cloud Data
 
The New Cloud World Order Is FinOps (Slideshow)
The New Cloud World Order Is FinOps (Slideshow)The New Cloud World Order Is FinOps (Slideshow)
The New Cloud World Order Is FinOps (Slideshow)
 
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdfQ4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
Q4 2023 Quarterly Investor Presentation - FINAL - v1.pdf
 
EMEA What is ThousandEyes? Webinar
EMEA What is ThousandEyes? WebinarEMEA What is ThousandEyes? Webinar
EMEA What is ThousandEyes? Webinar
 

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 #angelfirecounts 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 (Don’t Repeat Yourself) Software development principle emphasized within the rails community REST (Representative State Transfer) Using identifiers 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: Gemfile Home to your GEM dependencies app This is where you’ll find your models, views, and controllers config As you would imagine, here lives your configurations; routes, etc. Saturday, November 20, 2010
  • 9. DIRECTORY BREAKDOWN CON’T 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 configuration (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 file 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 don’t 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 config/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. WHAT’S MISSING? Posts Comments (haters gone hate) Tags / Keywords (I’m 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 config/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="field"> <%= f.label :email %><br /> <%= f.text_field :email %> </div> <div class="field"> <%= f.label :content %><br /> <%= f.text_area :content %> </div> <div class="actions"> <%= f.submit %> </div> <% end %> app/views/posts/show.html.erb @post = Post.find(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 :confirmation => 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 we’ll 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

Hinweis der Redaktion

  1. - Released Ruby on Rails as open source in July 2004, but did not share commit rights to the project until February 2005.
  2. - Released Ruby on Rails as open source in July 2004, but did not share commit rights to the project until February 2005.
  3. - Released Ruby on Rails as open source in July 2004, but did not share commit rights to the project until February 2005.
  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.