indmill / finder_filter Goto Github PK
View Code? Open in Web Editor NEWThis project forked from pelargir/finder_filter
An easy way to add common finders to your Rails controllers.
License: MIT License
This project forked from pelargir/finder_filter
An easy way to add common finders to your Rails controllers.
License: MIT License
= Synthesis An easy way to add common finders to your Rails controllers. == Installation gem sources -a http://gems.github.com (you only have to do this once) sudo gem install pelargir-finder_filter To use with a Rails 2.1 app, edit the environment.rb file and add an entry for the gem to the Rails::Initializer config block. == Usage finder_filter is intended to replace one-off before filters that you might commonly write in your Rails controllers. For example: class UsersController < ActionController::Base before_filter :find_user, :only => [:show, :edit] def show # do something with @user end def edit # do something with @user end def find_user @user = User.find(params[:id) end end finder_filter reduces this pattern to a single line: class UsersController < ActionController::Base finder_filter :only => [:show, :edit] def show; end def edit; end end Or, if you want to specify the model to find: class UsersController < ActionController::Base finder_filter :user, :only => [:show, :edit] def show; end def edit; end end To find based on a column other than ID: finder_filter :user, :by => :name # equivalent to: # @user = User.find_by_name(params[:id]) To find based on a param other than ID: finder_filter :user, :param => :permalink # equivalent to: # @user = User.find(params[:permalink]) Finally, you can specify that prepend_before_filter is used: finder_filter :user, :only => [:show, :edit], :prepend => true # generates: # prepend_before_filter :find_user, :only => [:show, :edit] The standard Rails :only and :except options can also be used: before_filter :find_user, :only => [:show, :edit] before_filter :find_user, :except => [:index] == Tests To run the tests: rake test == Dependencies actionpack > 2.0.1 mocha > 0.5.6 test-spec > 0.4.0 == Git git://github.com/pelargir/finder_filter.git == Contributors Matthew Bass, Kevin Smith
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.