0
我在軌道4,我試圖使用slu to使我的標籤網址漂亮。我接着是question。但它不起作用。這是我的代碼。Rails:Friendly_id的標籤與acts_as_taggable_on
我爲我的標籤列生成了一個slu g。
class AddSlugTotaggings < ActiveRecord::Migration
def change
add_column :tags, :slug, :string
add_index :tags, :slug
end
end
我創建了一個初始化:
ActsAsTaggableOn::Tag.class_eval do
extend FriendlyId
friendly_id :name, use: :slugged
end
但是,當我檢查我的標籤在控制檯中,嵌入列是零。
例如,來自命令行:
Tag.find(1)返回:
SELECT "tags".* FROM "tags" WHERE "tags"."id" = ? LIMIT 1 [["id", 1]]
=> #<Tag id: 1, name: "testtag", taggings_count: 1, slug: nil>
編輯:
這是我的控制器:tags_controller.rb
class TagsController < ApplicationController
def index
@tags = ActsAsTaggableOn::Tag.all
end
def show
@tag = ActsAsTaggableOn::Tag.find(params[:id])
@pins = Pin.tagged_with(@tag.name)
end
end
當我訪問url/tags/1時效果很好。但是,如果我試圖訪問/標籤/啓動它不會在這裏工作是錯誤:
Couldn't find ActsAsTaggableOn::Tag with 'id'=startup
它仍然無法正常工作。我編輯我的問題艱難。 – zacchj