I was working with Refinery cms some times back.I want blogging facility to my CMS. Refinery has various engine which can easily plug and play including blogging.
Blog Engine doesn’t facilitate with searching facility default,but it’s easy to add searching facility.
Following Snippet will help you to do this.
# app/models/refinery/blog/post.rb
module Refinery
module Blog
class Post < ActiveRecord::Base
........
.......
class << self
......
# Considering "refinery" is a prefix so table name is refinery_blog_posts
def search(search_string="")
Post.includes(:categories,:tags).live.where(
"refinery_blog_posts.title like (?) or refinery_blog_posts.body like (?)
or refinery_blog_categories.title like (?) or tags.name like (?)",
"%#{search_string}%","%#{search_string}%","%#{search_string}%","%#{search_string}%")
end
end
end
end
end
Now if you want you can add search method in controller or you can use index method for this.
Following Snippet will help us to search a blog posts.
# app/controllers/refinery/blog/posts_controller.rb
module Refinery
module Blog
class PostsController < BlogController
.....
def search
@posts = Post.search(params[:search]).page(params[:page])
render "refinery/blog/posts/index"
end
....
end
end
end
Now you are ready with Refinery CMS with Blog engine with Searching facility.
Any tips and tricks and feedback is welcome