Skip to content

Instantly share code, notes, and snippets.

@choyno
Created May 30, 2013 02:42
Show Gist options
  • Save choyno/5675435 to your computer and use it in GitHub Desktop.
Save choyno/5675435 to your computer and use it in GitHub Desktop.
class Post < ActiveRecord::Base
attr_accessible :text, :title, :user_id, :category_id
validates :title, presence: true
validates :category_id, presence: true
validates_length_of :title, maximum:15
validates :text, presence:true
belongs_to :user
has_many :comments, :dependent => :destroy, foreign_key: :post_id
belongs_to :category
scope :recent, order("created_at Desc")
scope :is_deleted_false, where(:is_deleted => false)
def self.search_title_body(search_by_title)
if(search_by_title)
where('title like ?', "%#{search_by_title}%")
end
end
def self.search_by_category(search_by_category)
if(search_by_title)
where('id like ?', "%#{search_by_category}%")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment