Ruby Rails:视频对象标签未更新

Ruby on Rails: video object tags not updating

视频对象有标签(通过 acts-as-taggable-on gem)。更新功能适用于除标签之外的所有视频属性。我不确定为什么。任何见解将不胜感激。

views/videos/_new.html.erb

      <div class="">
        <%= f.label(:tag_list, "Tags (separated by commas)") %></br >
        <%= f.text_field :tag_list, multiple: true, class: "form-control" %>
      </div>

videos_controller.rb

  def edit
    @video = Video.find(params[:id])
    @post = @video.post
  end

  def update
    @video = Video.find(params[:id])
    @post = @video.post
    @video.update_attributes(video_params)
    if current_user == @video.user
      if @video.save
        flash[:notice] = "Video successfully updated!"
        redirect_to video_path(@video)
      else
        flash[:notice] = "Video was not updated."
        @errors = @video.errors.full_messages.join(", ")
        flash[:alert] = @errors
        render action: "edit"
      end
    else
      flash[:notice] = "Only OP can edit video"
      refresh :edit
    end
  end

  private

  def video_params
    params.require(:video).permit(
      :title,
      :url,
      :tag_list,
    )
  end

看起来你的 video_params 正在过滤它。

尝试

 params.require(:video).permit(
      :title,
      :url,
      tag_list: []
    )