Last active
January 2, 2017 11:01
-
-
Save rockyjia/0dea90505ada299df3f8274488b392cf to your computer and use it in GitHub Desktop.
posts_controller.rb
This file contains hidden or 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 :authenticate_user!, :only => [:new, :create, :update, :destroy] | |
| def new | |
| @group = Group.find(params[:group_id]) | |
| @post = Post.new | |
| end | |
| def show | |
| end | |
| def edit | |
| @group = Group.find(params[:group_id]) | |
| @post = Post.find(params[:id]) | |
| end | |
| def create | |
| @group = Group.find(params[:group_id]) | |
| @post = Post.new(post_params) | |
| @post.group = @group | |
| @post.user = current_user | |
| if @post.save | |
| redirect_to group_path(@group) | |
| else | |
| render :new | |
| end | |
| end | |
| def update | |
| @post = Post.find(params[:id]) | |
| if @post.update(post_params) | |
| redirect_to account_posts_path, notice: "update success" | |
| else | |
| render :edit | |
| end | |
| end | |
| def destroy | |
| @post = Post.find(params[:id]) | |
| @post.destroy | |
| redirect_to account_posts_path, alert: "Post deleted." | |
| end | |
| private | |
| def post_params | |
| params.require(:post).permit(:content) | |
| end | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
app/controllers/posts_controller.rb