Skip to content

Instantly share code, notes, and snippets.

@davit-khaburdzania
Created April 25, 2019 18:21
Show Gist options
  • Save davit-khaburdzania/668e3dd9540dfeb80feb75df43cb504b to your computer and use it in GitHub Desktop.
Save davit-khaburdzania/668e3dd9540dfeb80feb75df43cb504b to your computer and use it in GitHub Desktop.
post controller
class PostsController < ApplicationController
def index
params[:tag] ? @posts = Post.tagged_with(params[:tag]) : @posts = Post.all
end
def show
@post = Post.find(params[:id])
end
def new
@post = Post.new
end
def create
@post = Post.new(post_params)
if @post.save
redirect_to @post
else
render :new
end
end
private
def post_params
params.require(:post).permit(:title, :content, :tag_list, :tag, { tag_ids: [] }, :tag_ids)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment