Every repository with this icon (
Every repository with this icon (
| name | age | message | |
|---|---|---|---|
| |
MIT-LICENSE | Wed Jun 18 08:52:17 -0700 2008 | |
| |
README.textile | Wed Jun 18 14:24:37 -0700 2008 | |
| |
Rakefile | Wed Jun 18 08:52:17 -0700 2008 | |
| |
init.rb | Wed Jun 18 08:52:42 -0700 2008 | |
| |
install.rb | Wed Jun 18 08:52:17 -0700 2008 | |
| |
lib/ | Fri Jun 20 11:19:41 -0700 2008 | |
| |
spec/ | Wed Jun 18 08:59:59 -0700 2008 | |
| |
tasks/ | Wed Jun 18 08:52:17 -0700 2008 | |
| |
uninstall.rb | Wed Jun 18 08:52:17 -0700 2008 |
HasParams
This plugin allows you to stop checking parameters via the params hash, in favor of a much cleaner alternative.
What’s the point?
Really, there is no point. And I wouldn’t be surprised if I were the only one to think this is worthy of using, but here it is anyway. Have you ever written a line of code similar to this?
Project.new(params[:project]) unless params[:project].blank?
To me, the params[:project].blank? part stinks up that line. So, I got rid of it. With has_params, you can do this instead:
Project.new(params[:project]) unless blank_project_params?
Much better.
Example(s)
You get a few ways to check for params with this plugin. Rather than explain them, I’ll just list the old way vs. the has_params way.
The “old way”
User.new(params[:user]) unless params[:user].blank?
User.new(params[:user]) if params[:user]
The “has_params way”
User.new(params[:user]) unless blank_user_params?
User.new(params[:user]) if has_user_params?
User.new(params[:user]) if user_params?
Note: <name>_params? is nothing more than a shorter way to call has_<name>_params?.
Gotcha!
One thing to keep in mind. Under the covers, this plugin uses method_missing and parses out the crapola to get to the actual params key. So, if you’re using method_missing somewhere in your controller (application_controller perhaps?), if it’s at all possible, make sure that you call super at some point. Otherwise, this plugin won’t work ;-)
License
Copyright © 2008 Ryan Heath, released under the MIT license







