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.new(params[:story]) story.save story.tag_with(params[:story][:tag_list]) story.save end 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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thought I''d ping the group. Anyone with solid acts_as_taggable experience who can tell me a better way to do the above? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I do not believe there is a better way to do this. The id must be created first to be stored in the taggable join table. On 1/21/07, bjhess <bjhess-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Thought I''d ping the group. Anyone with solid acts_as_taggable > experience who can tell me a better way to do the above? > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 1/12/07, bjhess <bjhess-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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.new(params[:story]) > story.save > story.tag_with(params[:story][:tag_list]) > story.save > endTry 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) } end end Now, in your controller: def save_story Story.create(params[:story]) end -- Chris Wanstrath http://errtheblog.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ask and you shall receive - check this out: http://blog.hasmanythrough.com/2007/1/22/using-faux-accessors-to-initialize-values --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---