Please Help.. On Apr 13, 2:21 pm, "K.Arunmohan" <[email protected]> wrote: > 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) %> > <div> > <%=check_box_tag "content_master[tag_id*s*][]", tag.id, > �...@content_master.tags.include?( > > > > > tag) %> > > <%= tag.name %> > > > </div> > > <% end %> > > Carefully look on the above code, I have changed tag_id to tag_ids. > > Then you have to change the create method as follows: > def create > �...@content_master = ContentMaster.new(params[:content_master]) > > > respond_to do |format| > > if @content_master.save > > #save images > > The above code will perfectly work > > On Tue, Apr 13, 2010 at 2:14 PM, Rahul Mehta <[email protected]>wrote: > > > Hiiii, > > > I have created one migration.. > > > 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 > > > C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/ > > associations/association_proxy.rb:262:in `raise_on_type_mismatch' > > C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/ > > associations/association_collection.rb:320:in `replace' > > C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/ > > associations/association_collection.rb:320:in `each' > > C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/ > > associations/association_collection.rb:320:in `replace' > > C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/ > > associations.rb:1325:in `tags=' > > D:/TestingGeek/trunk/Site/app/controllers/ > > content_masters_controller.rb:64:in `create' > > > and in my model code is > > has_and_belongs_to_many :content_masters > > has_and_belongs_to_many :tags > > > i have give as respective model.. > > > please help this is urgent.. > > > thanks > > > rahul.. > > > -- > > You received this message because you are subscribed to the Google Groups > > "Ruby on Rails: Talk" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]<rubyonrails-talk%[email protected]> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en.
-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

