Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
continue with the posts
Browse files Browse the repository at this point in the history
  • Loading branch information
dmathieu committed Dec 13, 2010
1 parent 2da6237 commit 7dde6d7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
22 changes: 22 additions & 0 deletions app/controllers/posts_controller.rb
@@ -1,9 +1,17 @@
class PostsController < ApplicationController
before_filter :get_post, :only => [:show, :edit, :update]

def show
end

def new
@post = Post.new
end

def edit
render :new
end

def create
@post = Post.new params[:post]

Expand All @@ -13,4 +21,18 @@ def create
render :new
end
end

def update
if @post.update_attributes params[:post]
redirect_to @post
else
render :new
end
end


private
def get_post
@post = Post.find params[:id]
end
end
2 changes: 1 addition & 1 deletion app/views/main/index.html.erb
@@ -1,5 +1,5 @@
<ul>
<% @posts.each do |p| %>
<li><%= p.title %></li>
<li><%= link_to p.title, p %></li>
<% end %>
</ul>
2 changes: 2 additions & 0 deletions app/views/posts/show.html.erb
@@ -0,0 +1,2 @@
<h1><%= @post.title %></h1>
<p><%= @post.content %></p>

0 comments on commit 7dde6d7

Please sign in to comment.