0
我正在爲使用act-as-taggable-on創建引腳時用戶輸入時創建的「標籤」字段。我已經運行遷移並編輯了form_html.erb,pins_controller.rb和pin.rb.使用act-as-taggable-on將標籤添加到不保存標籤的標籤
標籤似乎並沒有保存,當我打開一篇文章進行編輯時,他們已經消失。
這裏是我的form_html.erb
<%= 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 %>
我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
我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
任何想法,爲什麼我似乎無法保存/輸入標籤?