【发布时间】:2011-12-20 12:03:57
【问题描述】:
我是 Rails 新手。我正在尝试在我的示例应用程序上实现作为可标记的行为。我可以使用 tag_list 输入多个标签,但在搜索它们时遇到问题。
这就是我得到的。
我使用脚手架用户来生成控制器和模型。
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.text :tags
t.timestamps
end
end
end
我的用户模型是
class User < ActiveRecord::Base
serialize :tags
acts_as_taggable_on :tags
scope :by_join_date, order("created_at DESC")
end
我的用户控制器
Class UsersController < ApplicationController
def index
@users = User.all
@search = User.tagged_with("Tag11")
end
...
...
...
end
在安装 gem 之后,我也没有对类 ActsAsTaggableOnMigration
在我看来,我在我的 _form、索引和显示 html 文件中将 :tags 替换为 :tag_list
<div class="field">
<%= f.label :tags %><br />
<%= f.text_field :tag_list %>
</div>
这是我在浏览器中得到的
您能帮我理解我在哪里犯了错误吗?
谢谢。
【问题讨论】:
-
你在视图中用@search做什么?
标签: ruby-on-rails-3 activerecord ruby-on-rails-3.1 tagging acts-as-taggable-on