Update owner tags via form

前端 未结 7 1836
Happy的楠姐
Happy的楠姐 2020-12-18 01:26

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 upd

7条回答
  •  青春惊慌失措
    2020-12-18 01:58

    I ended up creating a virtual attribute that runs the User.tag statement:

    In my thing.rb Model:

    attr_accessible :tags
    belongs_to :user
    acts_as_taggable
    
    def tags
        self.all_tags_list
    end
    
    def tags=(tags)
        user = User.find(self.user_id)
        user.tag(self, :with => tags, :on => :tags, :skip_save => true)
    end
    

    The only thing you have to do is then change your views and controllers to update the tag_list to tags and make sure you set the user_id of the thing before the tags of the thing.

提交回复
热议问题