Rails 2.0 deprecations

Journal entry
March 13, 2007

The Rails core team is cleaning up. That’s obviously a good thing, however it does leave us facing a kabillion deprecation warnings when running tests and whatnot.

Unfortunately the official deprecations page appears to have been thrown together quickly after someone noticed that Rails 1.2 had been pushed out without anyone finishing the page that all deprecation warnings were referring to.

So what does a smart Rails developer who wants to be ready for Rails 2.0 when that time comes around do? She reads on…

end_form_tag is deprecated

The old, deprecated way The new, supported way
<%= start_form_tag %>
  ...stuff...
<%= end_form_tag %>
<% form_tag do %>
  ...stuff...
<% end %>
<%= form_remote_tag %>
  ...stuff...
<%= end_form_tag %>
<% form_remote_tag do %>
  ...stuff...
<% end %>

Object transactions are deprecated

The old, deprecated way The new, supported way
Model.transaction(foo) do
  ...stuff...
end
Model.transaction do
  ...stuff...
end

server_settings has been renamed smtp_settings

The old, deprecated way The new, supported way
ActionMailer::Base.server_settings = { 
  :address  => 'my.smtp.srv'
}
ActionMailer::Base.smtp_settings = {
  :address  => 'my.smtp.srv'
}

start_form_tag is deprecated

The old, deprecated way The new, supported way
<%= start_form_tag %>
  ...stuff...
<%= end_form_tag %>
<% form_tag do %>
  ...stuff...
<% end %>

You called count([“field = ?”, value], nil)

The old, deprecated way The new, supported way
model_or_association.count(['field = ?', value])
model_or_association.count(:conditions => ['field = ?', value])

You’ve called image_path with a source that doesn’t include an extension

The old, deprecated way The new, supported way
<%= image_tag 'foo' %>
<%= image_tag 'foo.png' %>

“But this isn’t complete either!”

Yeah, I know, thanks for pointing it out, though. The above messages are basically just the ones I have encountered in my projects. I will continue to update this page as I encounter more. Or even better, the Rails team could grab the above HTML and merge it with the stuff already on rubyonrails.org, making for what might just be a usable deprecation page.

Until then, hopefully this page will help out a few people.

Categories
,
Selling out
Did you know?
Jakob is an independent web application developer who builds awesome stuff for the web. You can hire him to build awesome stuff for you.

Comments and Trackbacks

Rob Sanheim March 13, 2007

There is also this:

http://wiki.rubyonrails.com/rails/pages/Deprecated+Patterns

UNC Chapel Hill Apartments March 28, 2007

Thanks for posting the above examples, I've been going through my application and trying to update everything.

Commenting on this entry has been closed.