# Does anyone know how to write an additional attribute to the

**URL:** <https://www.ruby-forum.com/t/does-anyone-know-how-to-write-an-additional-attribute-to-the/110035>\
**Category:** Rails\
**Created:** [July 21, 2007, 7:43pm UTC](https://www.ruby-forum.com/t/does-anyone-know-how-to-write-an-additional-attribute-to-the/110035 "2007-07-21T19:43:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 21, 2007, 7:43pm UTC](https://www.ruby-forum.com/t/does-anyone-know-how-to-write-an-additional-attribute-to-the/110035/1 "2007-07-21T19:43:58Z")

</div>

I’m enjoying using acts\_as\_taggable and am trying many ways to write  
an addtional integer key field to the tag.rb so it can in turn  
belong\_to a parent table.  
I’ve tried opening up the acts\_as\_taggable.rb trying to find a way to  
add another attribute but it’s so WEIRD??  
Then, I thought I would simply use a before\_create callback on the  
tag.rb model. Inside the controller.action that calls this method  
there are some instance variables available. However, when I reference  
this instance variable while taking a slight detour into the tag.rb  
code it becomes unavailable?  
In the controller.create I call this code:  
@rateme = @slicehit.ratemes.new(params[:rateme])  
@rateme.user = current\_user  
@rateme.tag\_with params[:tags] if params[:tags]  
respond\_to do |format|  
if @rateme.save

However in the before\_create code in the TAG model I use this;  
def after\_create  
self.portal\_id = @slicehit.portal\_id  
end  
I always get the “nil.portal\_id error”, although you can see the  
@slicehit is healthy in the calling code?  
Has anyone out there ever modified this part of acts\_as\_taggable?  
Thank you,  
Kathy

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 22, 2007, 9:57am UTC](https://www.ruby-forum.com/t/does-anyone-know-how-to-write-an-additional-attribute-to-the/110035/2 "2007-07-22T09:57:57Z")

</div>

removed\_email\_address@domain.invalid wrote:

> I’m enjoying using acts\_as\_taggable and am trying many ways to write  
> an addtional integer key field to the tag.rb so it can in turn  
> belong\_to a parent table.

why would you want to do this? what use do u need for a belongs\_to for  
tags?  
the whole idea of tags is that it belongs\_to

belongs\_to :taggable, :polymorphic =\> true

anything you want. you don’t need to add a belong\_to statement; it is  
true for each ‘taggable’ you define. ( you turn a model into a  
‘taggable’ object by adding the acts\_as\_taggable statement to the model.  
)

i may be missing something, though …

?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 22, 2007, 3:00pm UTC](https://www.ruby-forum.com/t/does-anyone-know-how-to-write-an-additional-attribute-to-the/110035/3 "2007-07-22T15:00:06Z")

</div>

Shai,  
Good question. I am writing on application that will serve MANY  
distinct domains by scoping the request.host. Many of these are  
entirely unrelated and thus my need to add a key integer field to the  
tag.rb.  
Somehow by putting the acts\_as\_? behavior on top of this object makes  
it act extraordinary and I can’t accomplish adding a row.column value  
to the record. This is a fundamental need and I can’t make headway. I  
am using the before\_create callback and it just passes through without  
ever appearing to fire. Here’s the code on callback:  
def after\_create  
self.portal = @portal.id  
end  
Do you know anyone I could hire to make this happen?  
Thank you,  
Kathleen

On Jul 22, 2:57 am, Shai R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 22, 2007, 3:12pm UTC](https://www.ruby-forum.com/t/does-anyone-know-how-to-write-an-additional-attribute-to-the/110035/4 "2007-07-22T15:12:16Z")

</div>

ok, so not that i have any real idea what EXACTLY you want to do, but  
just reading through what you’ve wrote:

> am using the before\_create callback and it just passes through without  
> ever appearing to fire. Here’s the code on callback:  
> def after\_create  
> self.portal = @portal.id  
> end

you’re using \*\* after\_create \*\* rather than \*\* before\_create \*\* and that  
in itself should be a good enough reason you aren’t saving anything -  
you are assigning  
“self.portal” after the record is saved.

this looks like a stupid solution to a bigger problem you’re having, but  
if this IS the prob, … there you go.

hth

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 22, 2007, 4:12pm UTC](https://www.ruby-forum.com/t/does-anyone-know-how-to-write-an-additional-attribute-to-the/110035/5 "2007-07-22T16:12:33Z")

</div>

I saw your original message and would like to help, but I don’t think  
it contained enough of your code to diagnose the problem. At least  
post the models…

Obie

On 7/22/07, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ever appearing to fire. Here’s the code on callback:
> 
> > > I’m enjoying using acts\_as\_taggable and am trying many ways to write  
> > > true for each ‘taggable’ you define. ( you turn a model into a
> 
> >

–  
Obie F.

> **[Best Online Casino in Australia | Top Licensed Casinos for Gamblers](https://toponlinecasinoaustralia.com)**
>
> Best Online Casino in Australia with licensed games only. Play blackjack, roulette, poker and other top-notch casino games. Enjoy gambling 24/7.

Pre-order my book The Rails Way today!  
[http://www.amazon.com/dp/0321445619](http://www.amazon.com/dp/0321445619)
