私はacts-as-taggable-onを使用していますが、これはしばらくの間把握しようとしていません。何らかの理由で、私はタグを表示したり、データベースの中に保存することはできません。私は本当にいくつかの助けが必要です、私はオンラインで見え、ドキュメントは中級者または初心者ではありません。ここに私のコードは次のとおりです。保存または表示されないタグは、なぜですか?
考案のユーザーモデル:
class User < ActiveRecord::Base
has_many :products, :dependent => :destroy
acts_as_tagger
end
製品モデル:
class Product < ActiveRecord::Base
attr_accessible :name, :date, :price, :tag_list
acts_as_taggable_on :tags
belongs_to :user
end
フォーム:
<div class="field">
<%= f.label :tag_list %>
<%= f.text_field :tag_list %>
</div>
ビューの表示:
<p>
<b>Tags:</b>
<%= @product.tag_list %>
</p>
更新しWORKINGコードでEDIT:
私はDeviseを使用してのみcurrent_user(製品テーブル内のuser_id)をさせるのです、このようななど、作成、破棄、更新タグなどのアクションを実行します。
ユーザーモデル:
class User < ActiveRecord::Base
has_many :products, :dependent => :destroy
acts_as_tagger
end
商品型番:
class Product < ActiveRecord::Base
attr_accessible :name, :date, :price, :tag_list, :longitude, :latitude
acts_as_taggable_on :tags
end
製品コントローラ:
class ProductsController < ApplicationController
before_filter :authenticate_user!
def index
@products = Product.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @products }
end
end
def show
@product = Product.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @product }
end
end
def new
@product = Product.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @product }
end
end
def edit
@product = current_user.products.find(params[:id])
@product.user = current_user
end
def create
@product = current_user.products.build(params[:product])
@product.user = current_user
respond_to do |format|
if @product.save
format.html { redirect_to(@product, :notice => 'Product was successfully created.') }
format.xml { render :xml => @product, :status => :created, :location => @product }
else
format.html { render :action => "new" }
format.xml { render :xml => @product.errors, :status => :unprocessable_entity }
end
end
end
def update
@product = current_user.products.find(params[:id])
@product.user = current_user
respond_to do |format|
if @product.update_attributes(params[:product])
format.html { redirect_to(@product, :notice => 'Product was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @product.errors, :status => :unprocessable_entity }
end
end
end
def destroy
@product = current_user.products.find(params[:id])
@product.destroy
respond_to do |format|
format.html { redirect_to(products_url) }
format.xml { head :ok }
end
end
end
の製品/ index.html.erb:
<td><%= product.tag_list %></td>
製品/ show.html.erb:
<p>
<b>Tags:</b>
<%= @product.tag_list %>
</p>
そのフォームのERBの外観と、コントローラの製品の外観はどうなっていますか? –
製品コントローラを表示するように更新しました。 – LearningRoR
'#@ product = Product.new(params [:product])のような行は、あなたのアプリでコメントアウトされていますか?つまり、何も救われないということです。それがあなたがコメントした理由なら、あなたのdevise/cancanの役割を修正する必要があります。 –