Cannot associate new records

After looking at a list of feeds, clicking on a specific feed gives an
interface to assign a tag to that feed with checkboxes. So far so good,
but http://localhost:3000/feeds/add_some_tags/1 gives:

ActiveRecord::HasManyThroughCantAssociateNewRecords in

Cannot associate new records through ‘Feed#colors’ on ‘#’. Both records
must have an id in order to create the has_many :through record
associating them.

That’s all well and good, but both records do have an id, of course.
However, how do I get those id’s and put them into the join table
(colors)? Now, this is getting interesting because it’s starting to
with the db directly. The models are at:
svn/trunk/app/models/ and look fine to me.

Part of the controller:

[email protected] ~/Desktop/strawr $
[email protected] ~/Desktop/strawr $ tail app/controllers/
feeds_controller.rb -n 20

def add_some_tags
@feed = Feed.find(params[:id])
@unused_tags =
Tag.find(:all) - @feed.tags

if @unused_tags.any?
@tags_to_add = { |tag|
(@params[‘tag’][‘checked’] == ‘1’)}
@tags_to_add.each { |tag|
@feed.tags << Tag.find_or_create_by_tag(params[:which_tag])}

if @tags_to_add.any? and
flash[:notice] = ‘Tags have been added!’
redirect_to :action => ‘show’, :id => @feed

[email protected] ~/Desktop/strawr $



This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs