Alumnus of Uni Augsburg
CTO of makandra GmbH
@triskweline
Can be combined with a bachelor's thesis or master's thesis
More info: http://start.makandra.de
We will learn to build a basic Rails application.
It's called You Look Nice Today.
Please share the paper screens.
puts 'Hello world!'
def say_hello(name)
puts "Hallo, #{name}!"
end
say_hello("Uni Augsburg")
say_hello "Uni Augsburg"
number.zero?
bucket.empty?
disk.erase!
nuclear_missile.launch!
def say_hello(name)
if !name.blank?
puts "Hello, \#{name}!"
end
end
def say_hello(name)
unless name.blank?
puts "Hello, \#{name}!"
end
end
def say_hello(name)
puts "Hello, \#{name}!" unless name.blank?
end
"foobar".length # returns 6
i = 5.25
i.floor # returns 5
i.ceil # returns 6
"foobar".class # returns String
"foobar".class.class # returns Class
shopping_list = ["Milk", "Toast", "Honey"]
shopping_list[1] # returns "Toast"
shopping_list.first # returns "Milk"
shopping_list.last # returns "Honey"
shopping_list = ["Milk", "Toast", "Honey"]
shopping_list.each do |item|
puts item
end
event "Rails-Workshop" do
time "24.01.2014 14:00"
place "Room 2045 N"
end
event "Frozen Rails conference" do
time "11.09.2014 09:00"
place "Helsinki"
end
We call these Domain Specific Languages (DSLs)
Rails is a DSL for web applications
class Greeter
def initialize(name)
@name = name
end
def say_hello
"Hello, #{@name}!"
end
end
greeter = Greeter.new("Mako")
greeter.say_hello # returns "Hello, Mako!"
The code below lives your server.
How can a web browser call say_hello
?
class Greeter
def initialize(name)
@name = name
end
def say_hello
"Hello, #{@name}!"
end
end
The code below lives your server.
How can a web browser call say_hello
?
class Greeter
def initialize(name)
@name = name
end
def say_hello
"Hello, #{@name}!"
end
end
Browser sends to server:
GET /say_hello?name=Mako HTTP/1.1
Host: nice.com
Server responds with:
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
<html>
<body>
Hello, Mako!
</body>
</html>
class WebApplication
def handle_request(request)
if request.path == '/say_hello'
model = Greeter.new(request.params[:name])
view = "<html>..." + model.say_hello + "...</html>"
return view
else
return '404 not found'
end
end
end
This is how web applications work in any language.
Rails is mostly syntactic sugar for the code above.
https://github.com/makandra/nice
(or use your paper screens)
https://github.com/makandra/nice
(or use your paper screens)
id | title | author_id |
---|---|---|
50 | The Bus Knight | 1001 |
51 | How to learn Ruby | 1001 |
52 | SQL in a Nutshell | 1003 |
id | screen_name | gender |
---|---|---|
1001 | Mako | f |
1003 | Raleigh | m |
SELECT * FROM posts WHERE author_id=1002
INSERT INTO users (name) VALUES ('Stacker')
UPDATE posts SET author_id=1001 WHERE author_id=1002
This is not the way you want to talk to a database.
User.create!(name: 'Stacker')
# INSERT INTO users (name) VALUES ('Stacker')
Post.count
# SELECT COUNT(*) FROM posts
user = User.find_by_name('Mako')
# SELECT FROM users WHERE name='Mako' LIMIT 1
user.posts.first.title
# SELECT title FROM posts WHERE author_id=1001
In the background ActiveRecord still generates SQL.
But we can talk to our data through an object-oriented interface.
https://github.com/makandra/nice
(or use your paper screens)
<form method="post" action="/users/create">
<label for="username">Username</label>
<input id="username" name="username" type="text">
<label for="email">E-mail</label>
<input id="email" name="email" type="text">
<label for="password">Password</label>
<input id="password" name="password" type="password">
<button type="submit">Register</button>
</form>
(abbreviated)
Despite being a universal pattern of UI interaction, nothing in HTML will help you implement a form roundtrip.
You must do everything by hand:
https://github.com/makandra/nice
(or use your paper screens)
https://github.com/makandra/nice
(or use your paper screens)
https://github.com/makandra/nice
(or use your paper screens)
Can be combined with a bachelor's thesis or master's thesis
More info: http://start.makandra.de