通过表单更新所有者标签

问题描述:

我想在我的应用中唯一地使用所有者标签.我的问题是,当我通过表单创建/更新帖子时,我只有 f.text_field :tag_list ,它只更新帖子的标签但没有所有者.如果我使用 f.text_field :all_tags_list 它不知道创建/更新的属性.我可以添加我的控制器:

I would like to uniquely use owner tags in my app. My problem is that when I create / update a post via a form I only have f.text_field :tag_list which only updates the tags for the post but has no owner. If I use f.text_field :all_tags_list it doesn't know the attribute on create / update. I could add in my controller:

User.find(:first).tag( @post, :with => params[:post][:tag_list], :on => :tags )

但后来我有重复的标签,用于帖子和所有者标签.我怎样才能只使用所有者标签?

but then I have duplicate tags, for post and for the owner tags. How can I just work with owner tags?

customersure (tsdbrown on SO) 在 https://github.com/mbleigh/acts-as-taggable-on/issues/111 对我有用

The answer proposed by customersure (tsdbrown on SO) on https://github.com/mbleigh/acts-as-taggable-on/issues/111 works for me

# In a taggable model:
before_save :set_tag_owner
def set_tag_owner
    # Set the owner of some tags based on the current tag_list
    set_owner_tag_list_on(account, :tags, self.tag_list)
    # Clear the list so we don't get duplicate taggings
    self.tag_list = nil
 end

# In the view:
<%= f.text_field :tag_list, :value => @obj.all_tags_list %>