Forum: Ruby on Rails find_all is now deprecated...how do I convert my code?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Lee S. (Guest)
on 2007-01-28 09:28
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:
<p><label for="ticket[priority_id]">Priority</label><br/>
<%= select('ticket','priority_id',Priority.find_all.collect {|p| [
p.priority, p.id ] }, { :prompt => "- Select -" }, { :style => "width:
150px" }) %></p>
Damian T. (Guest)
on 2007-01-28 09:59
(Received via mailing list)
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:

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

Your sincerely,
Damian/Three-eyed Fish
Lee S. (Guest)
on 2007-01-28 10:27
(Received via mailing list)
Well sure enough...thanks again for the tip!
Jakob S. (Guest)
on 2007-01-28 14:33
(Received via mailing list)
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:
> <p><label for="ticket[priority_id]">Priority</label><br/>
> <%= select('ticket','priority_id',Priority.find_all.collect {|p| [
> p.priority, p.id ] }, { :prompt => "- Select -" }, { :style => "width:
> 150px" }) %></p>

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

--
Jakob S. - http://mentalized.net
Theron P. (Guest)
on 2007-01-28 15:19
(Received via mailing list)
>From the command line:

find . | grep -i "\.rb$" | xargs ruby -p -i -e 'gsub(/find_all/i,
"find(:all)")'
Phlip (Guest)
on 2007-01-28 17:24
(Received via mailing list)
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:
>> > <p><label for="ticket[priority_id]">Priority</label><br/>
>> > <%= select('ticket','priority_id',Priority.find_all.collect {|p| [
>> > p.priority, p.id ] }, { :prompt => "- Select -" }, { :style => "width:
>> > 150px" }) %></p>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:

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

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
  http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Theron P. (Guest)
on 2007-01-29 03:57
(Received via mailing list)
Good point Philip, however I had success with it when using it to
change @session to session, @param to param, etc....
This topic is locked and can not be replied to.