I've migration tags_words
class CreateTagsWords < ActiveRecord::Migration
def change
create_table :tags_words, id: false do |t|
t.references :tag
t.references :word
end
add_index :tags_words, :tag_id
add_index :tags_words, :word_id
end
end
model words and tags:
class Word < ActiveRecord::Base
attr_accessible :namelanguage1, :namelanguage2, :tags_attributes
has_and_belongs_to_many :tags
def self.search(search)
if search
find(:all, :conditions => ['namelanguage1 LIKE ?', "%#{search}%"])
else
find(:all)
end
end
end
class Tag < ActiveRecord::Base
attr_accessible :name, :language_user_id
has_and_belongs_to_many :words
def self.search(search)
if search
find(:all, :conditions => ['name LIKE ?', "%#{search}%"])
else
find(:all)
end
end
end
and when I'll add tags to words and then save it doesn't save in db (when I write in rails console Words.find(1).tags
i get empty array.