通过表单更新所有者标签 [英] Update owner tags via form

查看:51
本文介绍了通过表单更新所有者标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用中唯一地使用所有者标签.我的问题是,当我通过表单创建/更新帖子时,我只有 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 %>

这篇关于通过表单更新所有者标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆