ActiveRecord::Relation issue on acts
I am a rails newbie. I am trying to implement acts-as-taggable-on on my sample app. I am able to enter multiple tags using tag_list but facing issues searching them.
This is what I got.
I used scaffold User to generate the controller & model.
class CreateUsers < ActiveRecord::Migration
  def change
    create_table :users do |t|
      t.string :name
      t.text :tags
      t.timestamps
    end
  end
end
My User Model is
class User < ActiveRecord::Base
  serialize :tags
  acts_as_taggable_on :tags
  scope :by_join_date, order("created_at DESC")  
end
My User controller
Class UsersController < ApplicationController
def index
    @users = User.all
    @search = User.tagged_with("Tag11")
end
...
...
...
end
I also did not make any changes to class ActsAsTaggableOnMigration < ActiveRecord::Migration after installing the gem.
In my view I replaced :tags with :tag_list in my _form, index & show html files
<div class="field">
<%= f.label :tags %><br />
<%= f.text_field :tag_list %>
</div>
This is what I get in the browser

Could you please help me understand where I am making a mistake?
Thank you.
 I'm guessing (because you haven't provided the code from your other view yet) but: when you do @search = User.tagged_with("Tag11") what is getting returned is not the tag names, but the actual tag objects.  If you have: <%= @search %> in your view, it won't work.  You'll need something like:  
<%= @search.map(&:name).join(', ') %>
or similar.
链接地址: http://www.djcxy.com/p/6102.html上一篇: 红宝石在轨道上
