Skip to content

Instantly share code, notes, and snippets.

@lmiller1990
Created September 28, 2018 04:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lmiller1990/52d94c38ce7a4eacc189e9fbebf42bca to your computer and use it in GitHub Desktop.
Save lmiller1990/52d94c38ce7a4eacc189e9fbebf42bca to your computer and use it in GitHub Desktop.
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