Created
October 21, 2010 09:48
-
-
Save TaopaiC/638220 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PostsController < ApplicationController | |
before_filter :find_forum | |
before_filter :find_post, :except => [:index, :new, :create] | |
def index | |
@posts = @forum.posts | |
end | |
def show | |
end | |
def new | |
@post = @forum.posts.build | |
end | |
def create | |
@post = @forum.posts.build(params[:post]) | |
if @post.save | |
redirect_to forum_post_path(@forum, @post) | |
else | |
render :new | |
end | |
end | |
def edit | |
end | |
def update | |
if @post.update_attribute(params[:post]) | |
redirect_to forum_post_path(@forum, @post) | |
else | |
render :edit | |
end | |
end | |
def destroy | |
@post.destroy | |
redirect_to forum_posts_path(@forum) | |
end | |
protected | |
def find_forum | |
@forum = Forum.find(params[:forum_id]) | |
end | |
def find_post | |
@post = @forum.posts.find(params[:id]) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment