Find_all is now deprecated...how do I convert my code?

I’m getting some deprecation warnings from some of my forms and I was
wondering how exactly I would convert them to the new format so it’s not
deprecated. I tried to do what it suggested but it’s not quite that
easy…I appreciate any help. Thanks!

Warning in the logs:
DEPRECATION WARNING: find_all is deprecated and will be removed from
Rails 2.0 (use find(:all, …)) See
http://www.rubyonrails.org/deprecation for details.

My select box on my form:

Priority
<%= select('ticket','priority_id',Priority.find_all.collect {|p| [ p.priority, p.id ] }, { :prompt => "- Select -" }, { :style => "width: 150px" }) %>

On Jan 28, 2007, at 10:28, Jl Smith wrote:

I’m getting some deprecation warnings from some of my forms and I was
wondering how exactly I would convert them to the new format so it’s
not
deprecated. I tried to do what it suggested but it’s not quite that
easy…I appreciate any help. Thanks!

I just globally replaced find_all with find(:all) in all project files,
and it works.

Yours may work too:

Priority
<%= select('ticket','priority_id',Priority.find(:all).collect {|p| [ p.priority, p.id ] }, { :prompt => "- Select -" }, { :style => "width: 150px" }) %>

Your sincerely,
Damian/Three-eyed Fish

Well sure enough…thanks again for the tip!

On Jan 28, 2007, at 08:28 , Jl Smith wrote:

I’m getting some deprecation warnings from some of my forms and I was
wondering how exactly I would convert them to the new format so
it’s not
deprecated. I tried to do what it suggested but it’s not quite that
easy…I appreciate any help. Thanks!
[SNIP]
My select box on my form:

Priority
<%= select('ticket','priority_id',Priority.find_all.collect {|p| [ p.priority, p.id ] }, { :prompt => "- Select -" }, { :style => "width: 150px" }) %>

Priority.find(:all).collect etc…


Jakob S. - http://mentalized.net

Theron Parlin

From the command line:

find . | grep -i “.rb$” | xargs ruby -p -i -e ‘gsub(/find_all/i,
“find(:all)”)’

Haw haw. That’s a joke, guys. Theron knows that your code should be so
well-factored that all your find_all’s only appear in very few places,
easy
to manually upgrade, and that each one will be too unique to submit do a
‘sed’ attack…

My select box on my form:

Priority
<%= select('ticket','priority_id',Priority.find_all.collect {|p| [ p.priority, p.id ] }, { :prompt => "- Select -" }, { :style => "width: 150px" }) %>

Priority.find(:all).collect etc...

And while we are on the subject of clean code, all that should be
correctly
blocked-out and indented, with named variables for intermediate values:

Priority
<%= priorities = Priority.find_all.collect{|p| [ p.priority, p.id ] } select 'ticket', 'priority_id', priorities, { :prompt => "- Select -" }, { :style => "width: 150px" } %>

Much easier to read, understand, and upgrade. Just because Ruby permits
these ultra-crunched super-long lines that doesn’t mean we should endure
them. Or put them in the Rails books…


Phlip
Redirecting... ← NOT a blog!!!

Good point Philip, however I had success with it when using it to
change @session to session, @param to param, etc…

From the command line:

find . | grep -i “.rb$” | xargs ruby -p -i -e ‘gsub(/find_all/i,
“find(:all)”)’