
Security News
New Website “Is It Really FOSS?” Tracks Transparency in Open Source Distribution Models
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
japetheape-scoped_search
Advanced tools
= scoped_search
The scoped_search Rails plugin makes it easy to search your ActiveRecord models. Searching is performed using a query string, which should be passed to the named_scope search_for that uses SQL LIKE %keyword% conditions for searching (ILIKE for Postgres). You can specify what fields should be used for searching.
== Installing
The recommended method to enable scoped_search in your project is adding the scoped_search gem to your environment. Add the following code to your Rails configuration in config/environment.rb:
Rails::Initializer.run do |config| ... config.gem 'wvanbergen-scoped_search', :lib => 'scoped_search', source => 'http://gems.github.com/' end
Run sudo rake gems:install to install the gem.
Another alternative is to install scoped_search as a Rails plugin:
script/plugin install git://github.com/wvanbergen/scoped_search.git
== Usage
First, you have to specify in what columns should be searched:
class User < ActiveRecord::Base searchable_on :first_name, :last_name end
Now, the search_for scope is available for queries. You should pass a query string to the scope. This can be empty or nil, in which case all no search conditions are set (and all records will be returned).
User.search_for(params[:q]).each { |project| ... }
You can also search on associate models. This works with belongs_to, has_one, has_many, has_many :through, and HABTM. For example if a User has_many Notes (title, content, created_at, updated_at)
class User < ActiveRecord::Base has_many: notes searchable_on :first_name, :last_name, :notes_title, :notes_content end
The search query language is simple. It supports these constructs:
This functionality is build on named_scope. The searchable_on statement creates a named_scope search_for. Because of this, you can actually chain the call with other scopes. For example, this can be very useful if you only want to search in projects that are accessible by a given user.
class Project < ActiveRecord::Base searchable_on :name, :description named_scope :accessible_by, lambda { |user| ... } end
Project.accessible_by(current_user).search_for(params[:q]).paginate(:page => params[:page], :include => :tasks)
== Additional resources
== License
This plugin is released under the MIT license. Please contact weshays (http://github.com/weshays) or wvanbergen (http://github.com/wvanbergen) for any questions.
FAQs
Unknown package
We found that japetheape-scoped_search demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.