Created
April 25, 2019 18:21
-
-
Save davit-khaburdzania/668e3dd9540dfeb80feb75df43cb504b to your computer and use it in GitHub Desktop.
post controller
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 | |
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