Skip to content

Instantly share code, notes, and snippets.

@abachman
Created August 12, 2010 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abachman/521545 to your computer and use it in GitHub Desktop.
Save abachman/521545 to your computer and use it in GitHub Desktop.
- form_for @screen do |f|
- Asset.all.each do |asset|
%label
= check_box_tag 'screen[asset_ids][]', asset.id, @screen.asset_ids.include?(asset.id)
= asset.name
= f.submit
# "model A"
class Screen < ActiveRecord::Base
has_and_belongs_to_many :assets
end
# "model B"
class Asset < ActiveRecord::Base
has_and_belongs_to_many :screens
default_scope :order => 'name'
end

On the first submission of the form, I can freely add associated models. Every subsequent submission fails, however, with:

ActiveRecord::AssociationTypeMismatch
Asset(#1234567) expected, got Asset(#7654321)

Commenting out the default_scope command in Asset "solved" the problem. i.e., I didn't get the error anymore.

This is using:

  • actionmailer (3.0.0.beta4)
  • actionpack (3.0.0.beta4)
  • activemodel (3.0.0.beta4)
  • activerecord (3.0.0.beta4)
  • activeresource (3.0.0.beta4)
  • activesupport (3.0.0.beta4)
  • arel (0.4.0)
  • pg (0.9.0)
  • rails (3.0.0.beta4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment