Tags 将标记添加到管脚,而不使用“作为可标记对象”保存标记

Tags 将标记添加到管脚,而不使用“作为可标记对象”保存标记,tags,acts-as-taggable-on,pins,Tags,Acts As Taggable On,Pins,我正在创建一个“标记”字段,供用户在使用act as taggable on创建PIN时输入。我已经运行了迁移并编辑了表单_html.erb、pins _controller.rb和pin.rb 标签似乎没有保存,当我打开一篇文章进行编辑时,它们就出现了 这是我的表格 <%= form_for @pin, html: { multipart: true } do |f| %> <% if @pin.errors.any? %> <div id="err

我正在创建一个“标记”字段,供用户在使用act as taggable on创建PIN时输入。我已经运行了迁移并编辑了表单_html.erb、pins _controller.rb和pin.rb

标签似乎没有保存,当我打开一篇文章进行编辑时,它们就出现了

这是我的表格

   <%= form_for @pin, html: { multipart: true } do |f| %>
 <% if @pin.errors.any? %>
   <div id="error_explanation">
    <h2><%= pluralize(@pin.errors.count, "error") %> prohibited this pin from being saved:</h2>

    <ul>
    <% @pin.errors.full_messages.each do |message| %>
    <li><%= message %></li>
  <% end %>
     </ul>
   </div>
 <% end %>

 <div class="form-group">
   <%= f.label :image %>
   <%= f.file_field :image, class: "form-control" %>
  </div>

  <div class="form-group">
<%= f.label :description %><br>
<%= f.text_field :description, class: "form-control" %>
  </div>
  <div class="form-group">
<%= f.label :date %><br>
<%= f.date_field :date, class: "form-control" %>
  </div>
  <div class="form-group">
  <%= f.label :tags, "Tags (separated by commas)"%><br />
  <%= f.text_field :tags_list%>
</div>
 <div class="actions">
    <%= f.submit %>
  </div>
 <% end %>

禁止保存此pin:



我的pins_controller.rb

class PinsController < ApplicationController
  before_action :set_pin, only: [:show, :edit, :update, :destroy]
  before_action :correct_user, only: [:edit, :update, :destroy]
  before_action :authenticate_user!, except: [:index, :show]



 def index
   @pins = Pin.all.order("created_at DESC").paginate(:page => params[:page], :per_page => 8)
 end

  def show
  end

  def new
    @pin = current_user.pins.build

  end

  def edit
  end

  def create
    @pin = current_user.pins.build(pin_params)
    if @pin.save
      redirect_to @pin, notice: 'Pin was successfully created.'
    else
      render action: 'new'
    end
  end

  def update
    if @pin.update(pin_params)
      redirect_to @pin, notice: 'Pin was successfully updated.'
    else
      render action: 'edit'
    end
  end

  def destroy
    @pin.destroy
    redirect_to pins_url
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_pin
      @pin = Pin.find(params[:id])
    end

        def correct_user
      @pin = current_user.pins.find_by(id: params[:id])
      redirect_to pins_path, notice: "Not authorized to edit this pin" if @pin.nil?
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def pin_params
      params.require(:pin).permit(:description, :image, :date, :tags)
    end
end
class PinsControllerparams[:page],:per\u page=>8)
终止
def秀
终止
def新
@pin=当前_user.pins.build
终止
定义编辑
终止
def创建
@pin=当前用户.pins.build(pin参数)
如果@pin.save
将_重定向到@pin,注意:“pin已成功创建。”
其他的
渲染操作:“新建”
终止
终止
def更新
如果@pin.update(pin_参数)
将_重定向到@pin,注意:“pin已成功更新。”
其他的
渲染操作:“编辑”
终止
终止
def销毁
@销
重定向到pins\u url
终止
私有的
#使用回调在操作之间共享公共设置或约束。
def设置针
@pin=pin.find(参数[:id])
终止
def正确的用户
@pin=当前用户.pins.find_by(id:params[:id])
重定向到pin路径,注意:如果@pin.nil,则“无权编辑此pin”?
终止
#永远不要相信来自恐怖网络的参数,只允许白名单通过。
def引脚参数
参数require(:pin).permit(:description,:image,:date,:tags)
终止
终止
我的pin.rb

class Pin < ActiveRecord::Base
     belongs_to :user
     has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" }
     validates_attachment_content_type :image, :content_type => ["image/jpg", "image/jpeg", "image/png"]
     acts_as_taggable
end
class Pin{:medium=>“300x300>”,:thumb=>“100x100>”}
验证附件内容类型:图像、内容类型=>[“图像/jpg”、“图像/jpeg”、“图像/png”]
充当可标记的角色
终止

你知道为什么我不能保存/输入标签吗?

我意识到我需要在pin.rb和pin\u controller.rb中使用标签列表,这解决了问题