# quick deprecation patch for Rails 2.0

**URL:** <https://discuss.rubyonrails.org/t/quick-deprecation-patch-for-rails-2-0/20496>\
**Category:** rubyonrails-core\
**Created:** [November 16, 2007, 2:02am UTC](https://discuss.rubyonrails.org/t/quick-deprecation-patch-for-rails-2-0/20496 "2007-11-16T02:02:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt11](https://avatars.discourse-cdn.com/v4/letter/m/ac91a4/32.png) [@Matt11](https://discuss.rubyonrails.org/u/Matt11)\
**Post date:** [November 16, 2007, 2:02am UTC](https://discuss.rubyonrails.org/t/quick-deprecation-patch-for-rails-2-0/20496/1 "2007-11-16T02:02:12Z")

</div>

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

[http://dev.rubyonrails.org/ticket/10181](http://dev.rubyonrails.org/ticket/10181)

---

<div class="post-metadata">

**Author:** ![Michael\_Koziarski1](https://avatars.discourse-cdn.com/v4/letter/m/aca169/32.png) [@Michael\_Koziarski1](https://discuss.rubyonrails.org/u/Michael_Koziarski1)\
**Post date:** [November 16, 2007, 2:38am UTC](https://discuss.rubyonrails.org/t/quick-deprecation-patch-for-rails-2-0/20496/2 "2007-11-16T02:38:14Z")

</div>

> Here is a really tiny patch to avoid another annoying deprecation warning 🙂
> 
> [http://dev.rubyonrails.org/ticket/10181](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'?

---

<div class="post-metadata">

**Author:** ![Matt11](https://avatars.discourse-cdn.com/v4/letter/m/ac91a4/32.png) [@Matt11](https://discuss.rubyonrails.org/u/Matt11)\
**Post date:** [November 16, 2007, 2:48am UTC](https://discuss.rubyonrails.org/t/quick-deprecation-patch-for-rails-2-0/20496/3 "2007-11-16T02:48:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael\_Koziarski1](https://avatars.discourse-cdn.com/v4/letter/m/aca169/32.png) [@Michael\_Koziarski1](https://discuss.rubyonrails.org/u/Michael_Koziarski1)\
**Post date:** [November 16, 2007, 4:20am UTC](https://discuss.rubyonrails.org/t/quick-deprecation-patch-for-rails-2-0/20496/4 "2007-11-16T04:20:31Z")

</div>

> 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?

---

<div class="post-metadata">

**Author:** ![Matt11](https://avatars.discourse-cdn.com/v4/letter/m/ac91a4/32.png) [@Matt11](https://discuss.rubyonrails.org/u/Matt11)\
**Post date:** [November 16, 2007, 8:02am UTC](https://discuss.rubyonrails.org/t/quick-deprecation-patch-for-rails-2-0/20496/5 "2007-11-16T08:02:08Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![Cheah\_Chu\_Yeow](https://avatars.discourse-cdn.com/v4/letter/c/9de0a6/32.png) [@Cheah\_Chu\_Yeow](https://discuss.rubyonrails.org/u/Cheah_Chu_Yeow)\
**Post date:** [November 16, 2007, 9:33am UTC](https://discuss.rubyonrails.org/t/quick-deprecation-patch-for-rails-2-0/20496/6 "2007-11-16T09:33:34Z")

</div>

> 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 &nbsp;&nbsp;def user\_id &nbsp;&nbsp;&nbsp;&nbsp;user.id &nbsp;&nbsp;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

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [November 18, 2007, 5:03pm UTC](https://discuss.rubyonrails.org/t/quick-deprecation-patch-for-rails-2-0/20496/7 "2007-11-18T17:03:56Z")

</div>

> > 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 ... &nbsp;&nbsp;\<calculated-earnings\>100000000000000000\</calculated-earnings\> &nbsp;&nbsp;\<real-earnings\>5\</real-earnings\> \</firm\>

There's also a :procs option.

Fred
