More Related Content
Similar to Rails - How does it work? (20)
Rails - How does it work?
- 1. A RAILS APP
How does it work?
@donschado
@klaustopher
Donnerstag, 21. November 13
- 4. URL
localhost:3000/
Request
GET /
Response
<html lang="en">
<head>
<title>Facebook Lite</title>
<link href="/assets/application.css" media="all" rel="stylesheet">
<script src="/assets/application.js"></script>
</head>
<body>
<div>
<h1>Das Neuste aus dem ganzen Netzwerk</h1>
<ul>
<li>
<img src="https://somewhere.github.com/1062e0f.png">
<div class="media-body">
<h4>Liane<small>19 Nov 20:32</small></h4>
<p>Ich bin hier!!!</p>
</div>
</li>
<li>
<img src="https://somwhere.github.com/fa47a113f69.png">
<div>
<h4>Marco<small>19 Nov 20:02</small></h4>
<p>Hallo, ist da wer?</p>
</div>
</li>
<li>
<img src="https://somwhere.github.com/fa47a113f69.png">
<div>
<h4>Marco<small>19 Nov 19:02</small></h4>
<p>Hallo Welt!</p>
</div>
</li>
</ul>
</div>
</body>
</html>
Router
routes.rb
Controller
<head>
<title>Facebook
Lite</title>
<%=
javascript_include_tag
"application"
%>
</head>
Partial
</div>
</body>
</html>
Donnerstag, 21. November 13
Layout
application.html.erb
post.rb
_post.html.erb
class Post < ActiveRecord::Base
end
...
</h1>
<%=
stylesheet_link_tag
"application",
media:
"all"
%>
<%=
yield
%>
Model
index.html.erb
<ul>
<%=
render
@posts
%>
</ul>
<html
lang="en">
<div
class="container">
get ’/’ => ‘welcome#index’
welcome_controller.rb
<h1>Das neuste aus
<body>
same as
class WelcomeController < ApplicationController
def index
@posts = Post....
end
end
View
Render
HTML
root ”welcome#index“
<li>
<%=
image_tag(post.user.avatar)
%>
<%=
post.user.name
%>
<%=
post.content
%>
</li>
Datenbank
db/schema.rb
create_table
t.text
t.integer
t.datetime
t.datetime
end
"posts" do |t|
"content"
"user_id"
"created_at"
"updated_at"