I have the requirement to empty the association records and add the association records as new (as below). @task = Task.find(params[:task_id]) @task.task_users = [] params[:ids].split(", ").each do |court_user_id| task_user = TaskUser.new(:court_user_id => court_user_id) @task.task_users << task_user end @task.save This is not working. Following error is thrown. ActiveRecord::AssociationTypeMismatch (TaskUser expected, got TaskUser): C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/associations/association_proxy.rb:148:in `raise_on_type_mismatch'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/associations/association_collection.rb:24:in `<<'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/associations/association_collection.rb:23:in `each'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/associations/association_collection.rb:23:in `<<'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/connection_adapters/abstract/database_statements.rb:59:in `transaction'' Any body know why this error has thrown for the above logic. Task.rb has the following code. belongs_to :court has_many :workflow_tasks has_many :task_users, :dependent => :destroy has_many :court_users, :through => :task_users I would appreciate if anyone can address this issue. Thanks, Ayyanar. A -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
At present, iam using the below logic to make the application work, but i don''t like this logic since you know the loopholes in the logic. No transaction. I want the above logic to work. @task = Task.find(params[:task_id]) TaskUser.delete_all("task_id=#{params[:task_id]}") params[:ids].split(", ").each do |court_user_id| task_user = TaskUser.new(:court_user_id => court_user_id, :task_id => params[:task_id]) task_user.save end -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
This is the same problem as your undefined method: the autoloading is getting screwed, probably because of you requiring a class by hand that you didn''t need to. This results in there being more than one instance of the TaskUser class hanging around: the one from before rails reset your application following the previous request and the one from the new request. Fred --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
ActiveRecord::AssociationTypeMismatch in ClistingsController#create Category(#-612181558) expected, got String(#-608036348) Rails.root: /home/gbolahan/sites/spotvilla Application Trace | Framework Trace | Full Trace app/controllers/clistings_controller.rb:45:in `new'' app/controllers/clistings_controller.rb:45:in `create'' I got the following error while trying to create a new set of listings. i hve arelationship between the category and clisting model. class Category < ActiveRecord::Base belongs_to :clisting end. class Clisting < ActiveRecord::Base has_one :category end -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
pls help in sorting this out -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 22 November 2011 11:50, gbolahan a. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> ActiveRecord::AssociationTypeMismatch in ClistingsController#create > > Category(#-612181558) expected, got String(#-608036348)Did you read the replies that were posted to the last time you asked this question? -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
yes i seemed to get it sorted the other time but the error is coming up again, in need to understand what might be causing this. -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 22 November 2011 11:57, gbolahan a. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> yes i seemed to get it sorted the other time but the error is coming up > again, in need to understand what might be causing this.The same thing... you''re passing a string to a method that expects an associated object. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
could you help me I how to identify where i am passing a string method instead of the associated object. -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 22 November 2011 12:24, gbolahan a. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> could you help me I how to identify where i am passing a string method > instead of the associated object.Look at the error you posted, it is telling you the file and line number Colin> > -- > Posted via http://www.ruby-forum.com/. > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- gplus.to/clanlaw -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 22 November 2011 12:24, gbolahan a. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> could you help me I how to identify where i am passing a string method > instead of the associated object.As I said before, you''ve probably got a form, with a field (probably a select drop-down) that you''ve called "category", which should be called "category_id". Inspect your params data, and see if what is being passed to update_attributes (I assume that''s what''s at line 45 of the clistings_controller) is what you expect. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Maybe Matching Threads
- Adding values from a db the rails way?
- AssociationTypeMismatch with RSpec 1.0.8, autotest running with drb
- Validation problems: ActiveRecord::AssociationTypeMismatch
- Validation problem with active record: AssociationTypeMismatch
- AssociationTypeMismatch / Model Caching in development envirnment