class TagContentMasterJoin < ActiveRecord::Migration
def self.up
create_table 'content_masters_tags' do |t|
t.column 'tag_id', :integer
t.column 'content_master_id', :integer
t.timestamps
end
end
def self.down
drop_table 'content_masters_tags'
end
end
for joining two tables
and in content_master view new want to save associated tag in the
above table for that i have written this code in content_master view
new
<% for tag in Tag.find(:all) %>
<div>
<%=check_box_tag "content_master[tag_id]", tag.id,
@content_master.tags.include?(tag) %>
<%= tag.name %>
</div>
<% end %>
and in my create function of content master controller following code
is present ..
def create
@content_master = ContentMaster.new
@content_master.tags=params[:content_master][:tag_id]
respond_to do |format|
if @content_master.save#save images
and some code here
but this all giving me this error
ActiveRecord::AssociationTypeMismatch in Content
mastersController#create
Tag(#46439460) expected, got String(#21132310)
RAILS_ROOT: D:/TestingGeek/trunk/Site
Application Trace | Framework Trace | Full Trace
I assume that u r following models:
class ContentMaster < ActiveRecord::Base
has_and_belongs_to_many :tags
end
class Tags < ActiveRecord::Base
has_and_belongs_to_many :content_masters
end
change ur view as:
<% for tag in Tag.find(:all) %>