Forum: Ruby on Rails acts_as_taggable and new taggable items

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
7be8427fa903a3329bb21313ce1e1e0a?d=identicon&s=25 bjhess (Guest)
on 2007-01-19 16:31
(Received via mailing list)
I just brought acts_as_taggable into an app and I have one question.
Is the following the best way to tag a brand new taggable item?  (Note:
I'm grabbing the data from a form - I cut the code down to its basics
for the post.)

def save_story
  story =[:story])

Near as I can tell, it's not possible to successfully tag a taggable
item until the item has an id.  Saving the item once before tagging
will generate that id for me, allowing me to save the item a second
time, which registers the tagging information.
7be8427fa903a3329bb21313ce1e1e0a?d=identicon&s=25 bjhess (Guest)
on 2007-01-21 21:23
(Received via mailing list)
Thought I'd ping the group.  Anyone with solid acts_as_taggable
experience who can tell me a better way to do the above?
B7518158455bc7567a06271f1b60d794?d=identicon&s=25 Nicholas Milkovits (Guest)
on 2007-01-22 01:01
(Received via mailing list)
I do not believe there is a better way to do this.  The id must be
first to be stored in the taggable join table.
B8dbb1987e8e5318584865f880036796?d=identicon&s=25 Chris Wanstrath (defunkt)
on 2007-01-22 01:15
(Received via mailing list)
On 1/12/07, bjhess <> wrote:

> end
Try keeping your controller skinny by adding accessors and callbacks
to your model.

class Story < ActiveRecord::Base
  after_save :tagify
  attr_accessor :tag_list

  def tagify
    self.tag_list = tag_list.split(',') if tag_list.is_a? String  #
comma, or whatever
    tag_list.each { |tag| tag_with(tag) }

Now, in your controller:

def save_story

Chris Wanstrath
3e6bbd5a01437feec48adf3838b15d91?d=identicon&s=25 askegg (Guest)
on 2007-01-22 11:33
(Received via mailing list)
Ask and you shall receive - check this out:
This topic is locked and can not be replied to.