Kevin Clark created quite a scene by blogging about old or deprecated features of Rails. The poor guy was just trying to help, but managed to bring upon himself the collective angst of the community.
This plugin tells you what techniques you are using that are out of fashion with the current Rails API. It is not an endorsement by the Rails core team or a guarantee that your code will work correctly. It just tries to identify common problems.
Install as a Rails plugin:
./script/plugin install http://topfunky.net/svn/plugins/deprecated
Run the rake task:
rake deprecated
Messages will be printed to the screen:
--> @flash
!! Use flash[] instead !!
.........................
helpers/user_helper.rb: notice = @flash[:notice]
--> @params
!! Use params[] instead !!
..........................
views/articles/_search.rhtml: text_field_tag('search_text', @params[:search_text])
--> @session
!! Use session[] instead !!
...........................
controllers/user_controller.rb: User.find(@session[:user_id])
--> component
!! Use of components are frowned upon !!
........................................
helpers/articles_helper.rb: render_component :layout => false,
--> find_all
!! Use find(:all) instead !!
............................
controllers/articles_controller.rb: @articles = Article.find_all
--> find_first
!! Use find(:first) instead !!
..............................
controllers/articles_controller.rb: @article = Article.find_first
--> paginate
!! The default paginator is slow. Writing your own may be faster !!
...................................................................
controllers/articles_controller.rb: @article_pages, @articles = paginate :articles, :order => 'created_at DESC'

One minor suggestion – include the -n flag with grep, so that we get line numbers.
This is excellent :)
Oh, and one other minor point – pagination and components aren’t deprecated yet, and even when they are moved out of core into plugins (which does seem likely), that doesn’t necessarily mean they’re unsupported.
Maybe have these warnings appear in some kind of ‘opinionated’ mode?
Nice plugin. Might be worth noting that it does not work on Winows boxes.
Now that is a real time saver! Cheers!
Thanks, I was wondering how badly I was missing out on some of this knowledge, because Kevin didn’t exactly site examples, but it seems not so bad at all.
One question I have is about components. I use them for areas like sidebars where it makes sense that they have their own separate action with controller code, because it has nothing to do with the current page. Kevin says I should just use partials, but what IS the better way I should be doing this?
In my instance, I have a real estate website, which calls a component in the layout. The component is an action and view that displays the most recently added properties in a sidebar.
Well done! I agree with James: opinionated mode would be nice for features that might be subpar but aren’t officially deprecated.
Thanks for posting this.
Well done! I agree with James: opinionated mode would be nice for features that might be subpar but aren’t officially deprecated.
Thanks for posting this.
Rockin’.
Great stuff !!
It also filters comments. I had this: #blah blah component
Thanks
I agree with James about the line numbers. I just updated the deprecated.rake file with a “-n” at the grep command and it works great!
Line numbers have been added. I’ll add a “strict” and “verbose” mode so you can ignore the component and pagination search.
I hope to rewrite it so it doesn’t use grep and will work on Windows also.
Thanks for the feedback!
Nice plugin. One issue I came across is that the script mistakes Enumerable’s “find_all” method for active_record’s “find_all” and mistakenly throws an error.
Very useful. Thanks!
Awesome! I’m running it on all my rails apps!
I’ve created a similar plugin that should work in tandem nicely with this one (for apple users only, sorry). It growls when a deprecated function is used. Check it out.
Odds that could export a function we could add it to our automated tests?
the salient goodbye
Hey! This really is very cool. I was actually thinking about creating a list of opinions on what was outdated and needed work within Rails just this morning. I still think that a formal list would be good: it’s a good way to show just what needs to be done within Rails, and perchance inspire those non-contributors to try it.
Well done! I honestly think ‘opinionated mode’ should be a default!
M.T.
Sorry about that “the salient goodbye”. That was definitely not meant to be put there ;)
And what about @request and @env ?
Nice plugin, thanks! I would also suggest adding support for identifying uses of render_partial and suggesting render :partial instead!
@env, @request, and render_partial have been added.
A test assertion would be nice…I’ll add that.
For those keeping score at home, try this:
Minor issue.
I’ve got an association named ‘components’ in one of my models. The rake task happily complains about this, even though it has nothing to do with rails ‘components’.
Quite useful, nonetheless.
Now that’s what I’m talkin’ bout. Thanks a million, TF.
Awesome… really cool idea to make such plugin.
thanks topfunky
Hey, I changed line 22 on vendor/plugins/deprecated/tasks/deprecated.rake to be like this after—exclude=.svn I added—exclude=.tmp so it became …. —exclude=.svn*—exclude=.tmp ....
because I was also showing .svn/.tmp files don’t know why…
nice plugin, very helpful
forgot to format it. should be like this:
—exclude=*.svn*—exclude=*.tmp
You may want to put in the pagination warning that Bruce Williams has a reasonably nice one available.
Very helpful, although like some mentioned above, if you are using another similar variable name (ex. ”@sessions”) or method name (ex. “render_partial_if_exists”) the script picks up on this. Adding some more regex to the deprecated terms could easily fix this.
Check out http://recaffeinated.com/files/jmlchanges.diff for a patch that makes the deprecated plugin a bit more friendly when it comes to variable and method names that include or are similar to those deprecated in rails.
This one is simmilar and gives at least some output on windows boxes http://topfunky.net/svn/plugins/deprecated/tasks/deprecated.rake
Love this plugin. Thanks guys.
I have added the deprecation checks in this plugin as well as many other deprecation checks to RailsCheck (http://railscheck.rubyforge.org/) – a semi-static Q/A verification tool for Ruby on Rails projects.
WoW!!! really nice work.. very useful. Thanks for sharing.
I believe usage of @headers should be replaced with response.headers[] as well.