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
FeedsController#add_some_tags
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
deal
with the db directly. The models are at: http://strawr.googlecode.com/
svn/trunk/app/models/ and look fine to me.
Part of the controller:
thufir@arrakis ~/Desktop/strawr $
thufir@arrakis ~/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 = @unused_tags.select { |tag|
(@params[‘tag’+tag.id.to_s][‘checked’] == ‘1’)}
@tags_to_add.each { |tag|
@feed.tags << Tag.find_or_create_by_tag(params[:which_tag])}
end
if @tags_to_add.any? and @feed.save
flash[:notice] = ‘Tags have been added!’
end
redirect_to :action => ‘show’, :id => @feed
end
end
thufir@arrakis ~/Desktop/strawr $
thanks,
Thufir