Skip to content

Commit 393c517

Browse files
committed
added blog
1 parent 8627ba2 commit 393c517

21 files changed

Lines changed: 315 additions & 10 deletions

.gems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
authlogic --version '=2.1.3'
22
hpricot
33
syntax
4+
bluecloth
45

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
class PostsController < ApplicationController
2+
# GET /posts
3+
# GET /posts.xml
4+
def index
5+
@posts = Post.all
6+
7+
respond_to do |format|
8+
format.html # index.html.erb
9+
format.xml { render :xml => @posts }
10+
end
11+
end
12+
13+
# GET /posts/1
14+
# GET /posts/1.xml
15+
def show
16+
@post = Post.find(params[:id])
17+
18+
respond_to do |format|
19+
format.html # show.html.erb
20+
format.xml { render :xml => @post }
21+
end
22+
end
23+
24+
# GET /posts/new
25+
# GET /posts/new.xml
26+
def new
27+
@post = Post.new
28+
29+
respond_to do |format|
30+
format.html # new.html.erb
31+
format.xml { render :xml => @post }
32+
end
33+
end
34+
35+
# GET /posts/1/edit
36+
def edit
37+
@post = Post.find(params[:id])
38+
end
39+
40+
# POST /posts
41+
# POST /posts.xml
42+
def create
43+
@post = Post.new(params[:post])
44+
45+
respond_to do |format|
46+
if @post.save
47+
flash[:notice] = 'Post was successfully created.'
48+
format.html { redirect_to(@post) }
49+
format.xml { render :xml => @post, :status => :created, :location => @post }
50+
else
51+
format.html { render :action => "new" }
52+
format.xml { render :xml => @post.errors, :status => :unprocessable_entity }
53+
end
54+
end
55+
end
56+
57+
# PUT /posts/1
58+
# PUT /posts/1.xml
59+
def update
60+
@post = Post.find(params[:id])
61+
62+
respond_to do |format|
63+
if @post.update_attributes(params[:post])
64+
flash[:notice] = 'Post was successfully updated.'
65+
format.html { redirect_to(@post) }
66+
format.xml { head :ok }
67+
else
68+
format.html { render :action => "edit" }
69+
format.xml { render :xml => @post.errors, :status => :unprocessable_entity }
70+
end
71+
end
72+
end
73+
74+
# DELETE /posts/1
75+
# DELETE /posts/1.xml
76+
def destroy
77+
@post = Post.find(params[:id])
78+
@post.destroy
79+
80+
respond_to do |format|
81+
format.html { redirect_to(posts_url) }
82+
format.xml { head :ok }
83+
end
84+
end
85+
end

app/helpers/posts_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module PostsHelper
2+
end

app/models/post.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Post < ActiveRecord::Base
2+
end

app/views/layouts/application.html.erb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
<body>
1414
<%= image_tag "hhhello.png", :id => "hello" %>
1515
<div id="nav">
16+
<%= link_to "Blog", blog_path %> |
17+
<%= link_to "Help", blog_path %> |
1618
<% if current_user %>
1719
<%= link_to "My messages", messages_path %> |
1820
<%= link_to "My page", user_path(current_user.username) %> |
@@ -23,8 +25,8 @@
2325
<%= link_to "Log in", login_path %>
2426
<% end %>
2527
</div>
26-
<div id="pitch">
27-
<%= yield %>
28+
<div id="pitch" class="clearfix">
29+
<%= yield %>
2830
</div>
2931
<%= yield :view_javascript %>
3032
</body>

app/views/layouts/posts.html.erb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2+
"http://www.w3.org/TR/html4/strict.dtd">
3+
4+
<html lang="en">
5+
<head>
6+
<meta charset="utf-8" />
7+
<title>Hackety Hack!</title>
8+
<%= stylesheet_link_tag "reset" %>
9+
<%= stylesheet_link_tag "ruby" %>
10+
<%= stylesheet_link_tag "application" %>
11+
<%= yield :head %>
12+
</head>
13+
<body>
14+
<%= image_tag "hhhello.png", :id => "hello" %>
15+
<div id="nav">
16+
<%= link_to "Blog", blog_path %> |
17+
<%= link_to "Help", blog_path %> |
18+
<% if current_user %>
19+
<%= link_to "My messages", messages_path %> |
20+
<%= link_to "My page", user_path(current_user.username) %> |
21+
<%= link_to "Edit info", edit_user_path(current_user.username) %> |
22+
<%= link_to "Log out", logout_path %>
23+
<% else %>
24+
<%= link_to "Sign up", new_user_path %> |
25+
<%= link_to "Log in", login_path %>
26+
<% end %>
27+
</div>
28+
<div id="posts" class="clearfix">
29+
<%= yield %>
30+
</div>
31+
<%= yield :view_javascript %>
32+
<script type="text/javascript">
33+
//<![CDATA[
34+
(function() {
35+
var links = document.getElementsByTagName('a');
36+
var query = '?';
37+
for(var i = 0; i < links.length; i++) {
38+
if(links[i].href.indexOf('#disqus_thread') >= 0) {
39+
query += 'url' + i + '=' + encodeURIComponent(links[i].href) + '&';
40+
}
41+
}
42+
document.write('<script charset="utf-8" type="text/javascript" src="http://disqus.com/forums/hacketyhack/get_num_replies.js' + query + '"></' + 'script>');
43+
})();
44+
//]]>
45+
</script>
46+
</body>
47+
</html>

app/views/posts/edit.html.erb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<h1>Editing post</h1>
2+
3+
<% form_for(@post) do |f| %>
4+
<%= f.error_messages %>
5+
6+
<p>
7+
<%= f.label :title %><br />
8+
<%= f.text_field :title %>
9+
</p>
10+
<p>
11+
<%= f.label :body %><br />
12+
<%= f.text_area :body %>
13+
</p>
14+
<p>
15+
<%= f.submit 'Update' %>
16+
</p>
17+
<% end %>
18+
19+
<%= link_to 'Show', @post %> |
20+
<%= link_to 'Back', posts_path %>

app/views/posts/index.html.erb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<% @posts.each do |post| %>
2+
<h1><%=h post.title %></h1>
3+
<h2><%=h post.created_at.to_s(:long) %></h2><br />
4+
<p><%=h post.body %></p><br />
5+
<p><%= link_to "", post_path(post) + "#disqus_thread" %></p>
6+
<hr />
7+
<% end %>

app/views/posts/new.html.erb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<h1>New post</h1>
2+
3+
<% form_for(@post) do |f| %>
4+
<%= f.error_messages %>
5+
6+
<p>
7+
<%= f.label :title %><br />
8+
<%= f.text_field :title %>
9+
</p>
10+
<p>
11+
<%= f.label :body %><br />
12+
<%= f.text_area :body %>
13+
</p>
14+
<p>
15+
<%= f.submit 'Create' %>
16+
</p>
17+
<% end %>
18+
19+
<%= link_to 'Back', posts_path %>

app/views/posts/show.html.erb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<h1><%= link_to @post.title, @post %></h1>
2+
<h2><%=h @post.created_at.to_s(:long) %></h2>
3+
<br />
4+
<p><%=h @post.body %></p>
5+
<br />
6+
<div id="disqus_thread"></div><script type="text/javascript" src="http://disqus.com/forums/hacketyhack/embed.js"></script><noscript><a href="http://disqus.com/forums/hacketyhack/?url=ref">View the discussion thread.</a></noscript><a href="http://disqus.com" class="dsq-brlink">blog comments powered by <span class="logo-disqus">Disqus</span></a>

0 commit comments

Comments
 (0)