PageRenderTime 1318ms CodeModel.GetById 39ms RepoModel.GetById 1ms app.codeStats 0ms

/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
  1. class PostsController < ApplicationController
  2. respond_to :html
  3. def show
  4. @post = Post.find(params[:id])
  5. end
  6. def index
  7. @search = Post.ransack(params[:q])
  8. @posts = @search.result.page(params[:page])
  9. end
  10. def new
  11. @post = Post.new
  12. end
  13. def create
  14. @post = Post.create(post_params)
  15. respond_with @post, location: -> { posts_path }
  16. end
  17. def edit
  18. @post = Post.find(params[:id])
  19. end
  20. def update
  21. @post = Post.find(params[:id])
  22. @post.update_attributes(post_params)
  23. respond_with @post
  24. end
  25. def destroy
  26. @post = Post.find(params[:id])
  27. @post.destroy
  28. respond_with @post
  29. end
  30. private
  31. def post_params
  32. params.require(:post).permit(:title, :body)
  33. end
  34. end