changing from id to ids will get assigned value implicitly.

Check the 32 and 33rd slide of the following URL:

http://www.slideshare.net/ihower/rails-best-practices

It may useful to you.


On Tue, Apr 13, 2010 at 2:59 PM, Rahul Mehta <[email protected]>wrote:

> Hiii K Arunmohan
>
> thanks for reply..
>
> i have change id to ids
>
> but in controller  create i can't do the exact same
> because me having following code in my controller
>
> def create
>    @content_master = ContentMaster.new
>     @content_master.title = params[:title]
>    @content_master.abstract_text = params[:abstract_text]
>    #...@content_master.image_path = imageObject.original_path
>    @content_master.content_text = params[:content_text]
>    @content_master.promote= params[:promote]
>    @content_master.promote_block= params[:promote_block]
>    @content_master.draft_state= params[:draft_state]
>    @content_master.parent_id=params[:content_master][:parent_id]
>    @content_master.tags=params[:content_master][:tag_ids]
>
>   if(params[:order_no_article]=='')
>    @content_master.order_no_article = 0
>   else
>    @content_master.order_no_article = params[:order_no_article]
>   end
>   # @content_master.promote = params[:promote]
>
>    #...@metadata = @content_master.metadata.build(params[:metadata ])
>     respond_to do |format|
>      if @content_master.save
>
>
> and it is still giving the same error..
>
> please suggest the solution..
>
> thanks
>
> rahul
>
>
> 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]>
> <rubyonrails-talk%[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]<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.

Reply via email to