Created
June 2, 2014 13:22
-
-
Save nicolaslazartekaqui/21d863ff0f1a7dc61cab to your computer and use it in GitHub Desktop.
This file contains 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
# app/models/bar.rb | |
class Bar < ActiveRecord::Base | |
include Searchable | |
end |
This file contains 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
# app/models/foo.rb | |
class Foo < ActiveRecord::Base | |
include Searchable | |
end |
This file contains 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
# app/models/concern/searchable.rb | |
module Searchable | |
extend ActiveSupport::Concern | |
included do | |
scope :term, ->(term) do | |
where { name.like("%#{term}%") } | |
end | |
end | |
end |
This file contains 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
# spec/concerns/searchable_spec.rb | |
require 'spec_helper' | |
describe Searchable do | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment