acts_as_taggable plugin

9 views
Skip to first unread message

elle

unread,
Jul 14, 2008, 5:07:13 AM7/14/08
to Beginning Ruby on Rails E-Commerce
Hi,

As you probably know, acts_as_taggable has been depreciated in rails
2. Also, there are differences between the gem and the plugin. I've
installed the plugin but I am unsure what I should change in the
application to make the plugin work?

Also, I've looked into: growing up your acts_as_taggable
http://blog.evanweaver.com/articles/2007/01/13/growing-up-your-acts_as_taggable/
... but I'm experiencing problems because the application in the book
uses foreign keys.

Would anyone have a solution to how I can make the application work
again (with either solution)?

TIA,
Elle

Jarkko Laine

unread,
Jul 23, 2008, 7:26:29 AM7/23/08
to railsec...@googlegroups.com

On 14.7.2008, at 12.07, elle wrote:

>
> Hi,
>
> As you probably know, acts_as_taggable has been depreciated in rails
> 2. Also, there are differences between the gem and the plugin. I've
> installed the plugin but I am unsure what I should change in the
> application to make the plugin work?
>
> Also, I've looked into: growing up your acts_as_taggable
> http://blog.evanweaver.com/articles/2007/01/13/growing-up-your-acts_as_taggable/
> ... but I'm experiencing problems because the application in the book
> uses foreign keys.

Could you elaborate on this a bit more? All belongs_to and habtm
relatioships use foreign keys, including the ones Evan describes in
the post.

> Would anyone have a solution to how I can make the application work
> again (with either solution)?

What's the problem you're having?

//jarkko

--
Jarkko Laine
http://jlaine.net
http://dotherightthing.com
http://www.railsecommerce.com
http://odesign.fi


elle

unread,
Jul 24, 2008, 2:29:46 AM7/24/08
to Beginning Ruby on Rails E-Commerce
Hi Jarkko,

I actually ended up using Acts as Taggable on Steroids. I eliminated
the foreign keys and used what the plugin offers.
http://agilewebdevelopment.com/plugins/acts_as_taggable_on_steroids
And it works great -- almost. Got one or two more things to fix but I
am sure this is more me than anything.

All the best,
Elle

On Jul 23, 11:26 pm, Jarkko Laine <jar...@jlaine.net> wrote:
> On 14.7.2008, at 12.07, elle wrote:
>
>
>
> > Hi,
>
> > As you probably know, acts_as_taggable has been depreciated in rails
> > 2. Also, there are differences between the gem and the plugin. I've
> > installed the plugin but I am unsure what I should change in the
> > application to make the plugin work?
>
> > Also, I've looked into: growing up your acts_as_taggable
> >http://blog.evanweaver.com/articles/2007/01/13/growing-up-your-acts_a...

Jarkko Laine

unread,
Jul 24, 2008, 2:46:32 AM7/24/08
to railsec...@googlegroups.com
Elle,

On 24.7.2008, at 9.29, elle wrote:
> Hi Jarkko,
>
> I actually ended up using Acts as Taggable on Steroids. I eliminated
> the foreign keys and used what the plugin offers.
> http://agilewebdevelopment.com/plugins/acts_as_taggable_on_steroids
> And it works great -- almost. Got one or two more things to fix but I
> am sure this is more me than anything.

Great that you got it sorted out. I'm still curious about what you
mean by eliminating foreign keys, though. You can't build an
association between two tables in a relational database without
foreign keys — unless you meant explicit foreign key constraints at
the database level, of course.

Cheers,

elle

unread,
Jul 24, 2008, 3:05:09 AM7/24/08
to Beginning Ruby on Rails E-Commerce
The plugin creates a migration for you that includes the following:
create_table :taggings do |t|
t.column :tag_id, :integer # foreign key; id of the tag
t.column :taggable_id, :integer # foreign key; id of the
taggable object

# You should make sure that the column created is
# long enough to store the required class names.
t.column :taggable_type, :string # taggable object type
(bookmark, photo, book, etcetera)

t.column :created_at, :datetime # timestamp
end

add_index :taggings, :tag_id
add_index :taggings, [:taggable_id, :taggable_type]

Excuse me as I might have changed the default migration it creates
(not exactly sure)... and in the same migration I dropped the
products_tags table. I had to manually define the tags again, which I
personally didn't mind, but if the site was bigger this might have
been a problem.
Does that answer your question??

Elle



On Jul 24, 6:46 pm, Jarkko Laine <jar...@jlaine.net> wrote:
> Elle,
>
> On 24.7.2008, at 9.29, elle wrote:
>
> > Hi Jarkko,
>
> > I actually ended up using Acts as Taggable on Steroids. I eliminated
> > the foreign keys and used what the plugin offers.
> >http://agilewebdevelopment.com/plugins/acts_as_taggable_on_steroids
> > And it works great -- almost. Got one or two more things to fix but I
> > am sure this is more me than anything.
>
> Great that you got it sorted out. I'm still curious about what you
> mean by eliminating foreign keys, though. You can't build an
> association between two tables in a relational database without
> foreign keys — unless you meant explicit foreign key constraints at
> the database level, of course.
>
> Cheers,
> //jarkko
>
> --

Jarkko Laine

unread,
Jul 24, 2008, 3:20:44 AM7/24/08
to railsec...@googlegroups.com

On 24.7.2008, at 10.05, elle wrote:

>
> The plugin creates a migration for you that includes the following:
> create_table :taggings do |t|
> t.column :tag_id, :integer # foreign key; id of the tag
> t.column :taggable_id, :integer # foreign key; id of the
> taggable object
>
> # You should make sure that the column created is
> # long enough to store the required class names.
> t.column :taggable_type, :string # taggable object type
> (bookmark, photo, book, etcetera)
>
> t.column :created_at, :datetime # timestamp
> end
>
> add_index :taggings, :tag_id
> add_index :taggings, [:taggable_id, :taggable_type]
>
> Excuse me as I might have changed the default migration it creates
> (not exactly sure)... and in the same migration I dropped the
> products_tags table. I had to manually define the tags again, which I
> personally didn't mind, but if the site was bigger this might have
> been a problem.
> Does that answer your question??

Not really, but that's ok :-)

taggings is basically the same thing as products_tags, it's just
promoted to a "real" model class instead of just being a join table.
Both of them must have the tag_id and taggable_id (or whatever you
name them) fields, which are foreign key fields.

What do you mean by "manually defining tags"?

//jarkko


>
>
> Elle
>
>
>
> On Jul 24, 6:46 pm, Jarkko Laine <jar...@jlaine.net> wrote:
>> Elle,
>>
>> On 24.7.2008, at 9.29, elle wrote:
>>
>>> Hi Jarkko,
>>
>>> I actually ended up using Acts as Taggable on Steroids. I eliminated
>>> the foreign keys and used what the plugin offers.
>>> http://agilewebdevelopment.com/plugins/acts_as_taggable_on_steroids
>>> And it works great -- almost. Got one or two more things to fix
>>> but I
>>> am sure this is more me than anything.
>>
>> Great that you got it sorted out. I'm still curious about what you
>> mean by eliminating foreign keys, though. You can't build an
>> association between two tables in a relational database without
>> foreign keys — unless you meant explicit foreign key constraints at
>> the database level, of course.
>>
>> Cheers,
>> //jarkko
>>
>> --
>> Jarkko Lainehttp://jlaine.nethttp://dotherightthing.comhttp://www.railsecommerce.comhttp
>> ://odesign.fi
> >

elle

unread,
Jul 24, 2008, 3:30:36 AM7/24/08
to Beginning Ruby on Rails E-Commerce
Oh yes, I didn't use the tags table th eplugin created because I
already had one.

And with manually I mean I redefined each product myself-- because I
dropped the products_tags table and when I did that I lost the already
defined relationships between the tags and products. (There might be a
better solution than this, probably.)

Elle
> >> Jarkko Lainehttp://jlaine.nethttp://dotherightthing.comhttp://www.railsecommerce....
> >> ://odesign.fi

Jarkko Laine

unread,
Jul 24, 2008, 3:36:55 AM7/24/08
to railsec...@googlegroups.com
On 24.7.2008, at 10.30, elle wrote:
> Oh yes, I didn't use the tags table th eplugin created because I
> already had one.
>
> And with manually I mean I redefined each product myself-- because I
> dropped the products_tags table and when I did that I lost the already
> defined relationships between the tags and products. (There might be a
> better solution than this, probably.)

Yeah, you could have just renamed the products_tags table to taggings
and add/edit fields. Or copy the data over inside the migration before
deleting the original table.

//jarkko

Reply all
Reply to author
Forward
0 new messages