intro to rails

32
Agile Web Development with Rails (for 3.1) @LVRUG - Jeremy Woertink Ya, that book

Upload: lvrubygroup

Post on 07-Nov-2014

611 views

Category:

Technology


0 download

DESCRIPTION

LVRUG meetup

TRANSCRIPT

Page 1: Intro to Rails

Agile Web Developmentwith Rails (for 3.1)

@LVRUG - Jeremy Woertink

Ya, that book

Page 2: Intro to Rails

What is "Rails" you ask?

"Ruby on Rails is a framework that makes it easier to develop, deploy, and maintain web applications."

"Rails applications are written in Ruby, a modern, object-oriented scripting language."

Page 3: Intro to Rails

•Web Development Framework•MVC Architecture•Written in Ruby•Convention over Configuration•RESTful•Agile•Clean

more info given in the Introduction section

What is "Rails" you ask?

Page 4: Intro to Rails

Who uses it?

Page 5: Intro to Rails

Websites on Rails•Yellow Pages•Groupon•Living Social•Github•Funny or Die!•Pololu•Cardplayer•ScripSmart•and lots of Russ's pr0n....

Page 6: Intro to Rails

Where's the start button?

Page 7: Intro to Rails

Installation

You're in luck, it's a gem! :)

$ sudo gem install rails

sudo may not be needed...

Page 8: Intro to Rails

Checklist•Know what it is? CHECK

Page 9: Intro to Rails

Checklist•Know what it is? CHECK•Know who uses it? CHECK

Page 10: Intro to Rails

Checklist•Know what it is? CHECK•Know who uses it? CHECK•Know where to get it? CHECK

Page 11: Intro to Rails

Checklist•Know what it is? CHECK•Know who uses it? CHECK•Know where to get it? CHECK•Know how to use it? NOPE. Chuck Testa

Page 12: Intro to Rails

Gettin' REAL dirty

$ cd websiteswebsites$ rails new demo create lots of stuff run bundle install Fetching source index for http://rubygems.org/ Your bundle is complete!

websites$ cd demodemo$ rails server=> Booting WEBrick => Rails 3.1.0 application starting in development on http://0.0.0.0:3000

Page 13: Intro to Rails

http://localhost:3000

Page 14: Intro to Rails

Hello, Rails!

demo$ rails generate controller Say hello goodbye create more stuff... invoke things route whatever

Page 15: Intro to Rails

Hello, Rails!

demo$ rails generate controller Say hello goodbye create more stuff... invoke things route whatever

Visit http://localhost:3000/say/hello

Page 16: Intro to Rails

ZOMG! What happened?

•created "SayController"•app/controllers/say_controller.rb

•created views for "say"•app/views/say/hello.html.erb•app/views/say/goodbye.html.erb

•updated routes with "say" routes•config/routes.rb

•created other super secret squirrel stuff (i.e. assets, tests, helper)

Page 17: Intro to Rails

app/controllers/say_controller.rb

class SayController < ApplicationController def hello end

def goodbye end

end

Page 18: Intro to Rails

app/controllers/say_controller.rb

Page 19: Intro to Rails

app/views/say/hello.html.erb

• say - The name of the controller• hello - The name of the action• html - The end format we want• js, xml, text...

• erb - The ruby templating system• haml, slim, mustache, liquid...

Page 20: Intro to Rails

app/views/say/hello.html.erb

<h1>Say#hello</h1><p>Find me in app/views/say/hello.html.erb</p>

Page 21: Intro to Rails

app/views/say/hello.html.erb

<h1>Hello from Rails!</h1><p>It is now <%= Time.now %></p>

Page 22: Intro to Rails

http://localhost:3000/say/hello

Page 23: Intro to Rails

app/controllers/say_controller.rb

class SayController < ApplicationController def hello @time = Time.now end

def goodbye end

end

Page 24: Intro to Rails

app/views/say/hello.html.erb

<h1>Hello from Rails!</h1><p>It is now <%= @time %></p>

Page 25: Intro to Rails

Fancy pants time!

Page 26: Intro to Rails

app/views/say/hello.html.erb

<h1>Hello from Rails!</h1><p>It is now <%= @time %></p><p> Time to say <%= link_to("Goodbye", say_goodbye_path) %>!</p>

Page 27: Intro to Rails

http://localhost:3000/say/hello

Page 28: Intro to Rails

app/views/say/goodbye.html.erb

<h1>Say#goodbye</h1><p>Find me in app/views/say/goodbye.html.erb</p>

Page 29: Intro to Rails

app/views/say/goodbye.html.erb

<h1>Beer time?</h1><blink>Holla atchya boy!</blink><span>Say<%= link_to("Hello", say_hello_path) %> again.</span>

Page 30: Intro to Rails

app/views/say/goodbye.html.erb

<h1>Beer time?</h1><blink>Holla atchya boy!</blink><span>Say<%= link_to("Hello", say_hello_path) %> again.</span>

ahh yeah, you love the blink tag don't ya!

Page 31: Intro to Rails

Recapitulation time!

• Installed rails• Created a new application• Generated controller and views• Added dynamic content• Linked pages together

Page 32: Intro to Rails

Questions?!