/app/controllers/posts_controller.rb
https://gitlab.com/lporras/text-search-example · Ruby · 44 lines · 34 code · 10 blank · 0 comment · 0 complexity · 42f20a31e030945c8ea7686c6e26b68f MD5 · raw file
- class PostsController < ApplicationController
- respond_to :html
- def show
- @post = Post.find(params[:id])
- end
- def index
- @search = Post.ransack(params[:q])
- @posts = @search.result.page(params[:page])
- end
- def new
- @post = Post.new
- end
- def create
- @post = Post.create(post_params)
- respond_with @post, location: -> { posts_path }
- end
- def edit
- @post = Post.find(params[:id])
- end
- def update
- @post = Post.find(params[:id])
- @post.update_attributes(post_params)
- respond_with @post
- end
- def destroy
- @post = Post.find(params[:id])
- @post.destroy
- respond_with @post
- end
- private
- def post_params
- params.require(:post).permit(:title, :body)
- end
- end