quick deprecation patch for Rails 2.0

Here is a really tiny patch to avoid another annoying deprecation
warning :slight_smile:

http://dev.rubyonrails.org/ticket/10181

Here is a really tiny patch to avoid another annoying deprecation
warning :slight_smile:

http://dev.rubyonrails.org/ticket/10181

What are you doing that triggers a warning?

Person.columns_hash["created_at"].type
=> :datetime

Type's our own attribute, not 'class'?

I'm adding attributes to the object before converting it to xml,
something like that:

@photo
@photo[:user_id] = @photo.user.id

render :xml => @photo.to_xml( :except =>
[:id, :filename, :updated_at, :height, :width], :skip_types => true)

Maybe the problem is that you can't easily add an attribute.

-Matt

I'm adding attributes to the object before converting it to xml,
something like that:

@photo
@photo[:user_id] = @photo.user.id

render :xml => @photo.to_xml( :except =>
[:id, :filename, :updated_at, :height, :width], :skip_types => true)

Maybe the problem is that you can't easily add an attribute.

I'm not sure that's something we intend to support. You should be
able to use, either :methods=>[:user_id] or a builder template to
achieve what you're after?

I'm not sure that's something we intend to support. You should be
able to use, either :methods=>[:user_id] or a builder template to
achieve what you're after?

From the RDoc:
to_xml is controlled with :only, :except, :skip_instruct, :skip_types
and :dasherize. The :only and :except options are the same as for the
attributes method. To not have the column type included in the XML
output, set :skip_types to true.

While that works great when you want to remove some attributes,
sometimes you simply want to add one attribute, creating a builder
template for that seems like an overkill to me.

Can you explain what you mean by using :methods=>[:user_id]?

Would it be bad to add another method to to_xml, such as #add?

One could do:

render :xml => @photo.to_xml( :except
=>[:id, :filename, :updated_at, :height, :width], :add => {:user_id =>
@photo.user.id})

What do you think?

-Matt

Can you explain what you mean by using :methods=>[:user_id]?

Here's an example of:

In your Photo class you can define a method 'user_id':

class Photo
  def user_id
    user.id
  end
end

Then get to_xml to include it when serializing with a :methods =>
[:user_id] option.

My opinion is that the :methods way should work for you quite well
(there's no need for the proposed :add option). Otherwise, Builder
templates is the way to go if you're going after something more
complicated.

Cheers,
Chu Yeow

I'm not sure that's something we intend to support. You should be
able to use, either :methods=>[:user_id] or a builder template to
achieve what you're after?

From the RDoc:
to_xml is controlled with :only, :except, :skip_instruct, :skip_types
and :dasherize. The :only and :except options are the same as for the
attributes method. To not have the column type included in the XML
output, set :skip_types to true.

The rdoc also says:

To include any methods on the object(s) being called use :methods
firm.to_xml :methods => [ :calculated_earnings, :real_earnings ]
<firm>
# ... normal attributes as shown above ...
  <calculated-earnings>100000000000000000</calculated-earnings>
  <real-earnings>5</real-earnings>
</firm>

There's also a :procs option.

Fred