# Insert some value into a result of a find in a db

**URL:** <https://www.ruby-forum.com/t/insert-some-value-into-a-result-of-a-find-in-a-db/162120>\
**Category:** Rails\
**Created:** [March 5, 2009, 10:58pm UTC](https://www.ruby-forum.com/t/insert-some-value-into-a-result-of-a-find-in-a-db/162120 "2009-03-05T22:58:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cinderedmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/74df32/32.png) [@cinderedmonkey](https://www.ruby-forum.com/u/cinderedmonkey)\
**Post date:** [March 5, 2009, 10:58pm UTC](https://www.ruby-forum.com/t/insert-some-value-into-a-result-of-a-find-in-a-db/162120/1 "2009-03-05T22:58:00Z")

</div>

Hi,  
I’m trying to insert a string component into what was found by a find  
search.  
E.g.  
do a  
@version = Version.find(“270”)  
@path = “somestring”  
And I would like to stick the @path string into @version  
then later do a  
render :xml =\> @version  
in order to produce  
  
  
“270”  
.  
.  
.  
“somestring”

Is this possible? The value of @path is not necessarily a result from  
a search in the db so I can’t combine two searches via something like  
a find\_by\_sql or include.

---

<div class="post-metadata">

**Author:** ![cinderedmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/74df32/32.png) [@cinderedmonkey](https://www.ruby-forum.com/u/cinderedmonkey)\
**Post date:** [March 6, 2009, 12:09am UTC](https://www.ruby-forum.com/t/insert-some-value-into-a-result-of-a-find-in-a-db/162120/2 "2009-03-06T00:09:05Z")

</div>

Should be no problem. You can add an attribute to @version and it will  
be emitted when you render.

Try it in the console.

@version = Version.find(…)  
@version[‘path’] = ‘somestring’  
@version.to\_xml

---

<div class="post-metadata">

**Author:** ![cinderedmonkey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/74df32/32.png) [@cinderedmonkey](https://www.ruby-forum.com/u/cinderedmonkey)\
**Post date:** [March 6, 2009, 12:36am UTC](https://www.ruby-forum.com/t/insert-some-value-into-a-result-of-a-find-in-a-db/162120/3 "2009-03-06T00:36:02Z")

</div>

Hey that’s great!  
Simple and sweet.  
Can I set the type?  
As it stands it’s coming out as type="NilClass"  
On the flip side, can I also remove the type info?  
thanks

On Mar 5, 6:08 pm, Martin S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
