-
-
Save lmiller1990/52d94c38ce7a4eacc189e9fbebf42bca 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 | |
def new | |
@post = Post.new | |
end | |
def create | |
@post = Post.new(post_params) | |
if @post.save | |
redirect_to @post | |
else | |
flash[:errors] = @post.errors.full_messages | |
render :new | |
end | |
end | |
def show | |
@post = Post.find params[:id] | |
end | |
def index | |
@posts = Post.all | |
end | |
private | |
def post_params | |
params.require(:post).permit(:title, :body, :category_id) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment