Eduardo Yáñez Parareda
2009-Oct-05 10:33 UTC
AssociationTypeMismatch expected Project got Project
Using RAILS_GEM_VERSION = ''2.1.2'' Hello, I''m developing a plugin for another rails app. When I try to show the new form view I got this error: ActiveRecord::AssociationTypeMismatch in Audit testsController#new Project(#70348727429120) expected, got Project(#70348730882020) RAILS_ROOT: /home/eyp/Aplicaciones/redmine-0.8.4 Application Trace | Framework Trace | Full Trace vendor/rails/activerecord/lib/active_record/associations/ association_proxy.rb:210:in `raise_on_type_mismatch'' vendor/rails/activerecord/lib/active_record/associations/ belongs_to_association.rb:22:in `replace'' vendor/rails/activerecord/lib/active_record/associations.rb:1114:in `project='' vendor/plugins/redmine_audit_tests/app/controllers/ audit_tests_controller.rb:13:in `new'' vendor/rails/actionpack/lib/action_controller/base.rb:1166:in `send'' vendor/rails/actionpack/lib/action_controller/base.rb:1166:in `perform_action_without_filters'' vendor/rails/actionpack/lib/action_controller/filters.rb:579:in `call_filters'' vendor/rails/actionpack/lib/action_controller/filters.rb:572:in `perform_action_without_benchmark'' vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'' /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'' vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'' vendor/rails/actionpack/lib/action_controller/rescue.rb:201:in `perform_action_without_caching'' vendor/rails/actionpack/lib/action_controller/caching/sql_cache.rb: 13:in `perform_action'' vendor/rails/activerecord/lib/active_record/connection_adapters/ abstract/query_cache.rb:33:in `cache'' vendor/rails/activerecord/lib/active_record/query_cache.rb:8:in `cache'' vendor/rails/actionpack/lib/action_controller/caching/sql_cache.rb: 12:in `perform_action'' vendor/rails/actionpack/lib/action_controller/base.rb:529:in `send'' vendor/rails/actionpack/lib/action_controller/base.rb:529:in `process_without_filters'' vendor/rails/actionpack/lib/action_controller/filters.rb:568:in `process_without_session_management_support'' vendor/rails/actionpack/lib/action_controller/session_management.rb: 130:in `process'' vendor/rails/actionpack/lib/action_controller/base.rb:389:in `process'' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:149:in `handle_request'' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:107:in `dispatch'' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:104:in `synchronize'' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:104:in `dispatch'' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:120:in `dispatch_cgi'' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:35:in `dispatch'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/rails.rb:76:in `process'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/rails.rb:74:in `synchronize'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/rails.rb:74:in `process'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:159:in `process_client'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `each'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `process_client'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `initialize'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `new'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `initialize'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `new'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `run'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/ configurator.rb:282:in `run'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/ configurator.rb:281:in `each'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/ configurator.rb:281:in `run'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:128:in `run'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/command.rb: 212:in `run'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:281 vendor/rails/activesupport/lib/active_support/dependencies.rb:503:in `load'' vendor/rails/activesupport/lib/active_support/dependencies.rb:503:in `load'' vendor/rails/activesupport/lib/active_support/dependencies.rb:355:in `new_constants_in'' vendor/rails/activesupport/lib/active_support/dependencies.rb:503:in `load'' vendor/rails/railties/lib/commands/servers/mongrel.rb:64 /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'' /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'' vendor/rails/activesupport/lib/active_support/dependencies.rb:510:in `require'' vendor/rails/activesupport/lib/active_support/dependencies.rb:355:in `new_constants_in'' vendor/rails/activesupport/lib/active_support/dependencies.rb:510:in `require'' vendor/rails/railties/lib/commands/server.rb:39 /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'' /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'' script/server:3 vendor/rails/activerecord/lib/active_record/associations/ association_proxy.rb:210:in `raise_on_type_mismatch'' vendor/rails/activerecord/lib/active_record/associations/ belongs_to_association.rb:22:in `replace'' vendor/rails/activerecord/lib/active_record/associations.rb:1114:in `project='' vendor/plugins/redmine_audit_tests/app/controllers/ audit_tests_controller.rb:13:in `new'' vendor/rails/actionpack/lib/action_controller/base.rb:1166:in `send'' vendor/rails/actionpack/lib/action_controller/base.rb:1166:in `perform_action_without_filters'' vendor/rails/actionpack/lib/action_controller/filters.rb:579:in `call_filters'' vendor/rails/actionpack/lib/action_controller/filters.rb:572:in `perform_action_without_benchmark'' vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'' /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'' vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'' vendor/rails/actionpack/lib/action_controller/rescue.rb:201:in `perform_action_without_caching'' vendor/rails/actionpack/lib/action_controller/caching/sql_cache.rb: 13:in `perform_action'' vendor/rails/activerecord/lib/active_record/connection_adapters/ abstract/query_cache.rb:33:in `cache'' vendor/rails/activerecord/lib/active_record/query_cache.rb:8:in `cache'' vendor/rails/actionpack/lib/action_controller/caching/sql_cache.rb: 12:in `perform_action'' vendor/rails/actionpack/lib/action_controller/base.rb:529:in `send'' vendor/rails/actionpack/lib/action_controller/base.rb:529:in `process_without_filters'' vendor/rails/actionpack/lib/action_controller/filters.rb:568:in `process_without_session_management_support'' vendor/rails/actionpack/lib/action_controller/session_management.rb: 130:in `process'' vendor/rails/actionpack/lib/action_controller/base.rb:389:in `process'' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:149:in `handle_request'' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:107:in `dispatch'' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:104:in `synchronize'' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:104:in `dispatch'' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:120:in `dispatch_cgi'' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:35:in `dispatch'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/rails.rb:76:in `process'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/rails.rb:74:in `synchronize'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/rails.rb:74:in `process'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:159:in `process_client'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `each'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `process_client'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `initialize'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `new'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `initialize'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `new'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `run'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/ configurator.rb:282:in `run'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/ configurator.rb:281:in `each'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/ configurator.rb:281:in `run'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:128:in `run'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/command.rb: 212:in `run'' /usr/lib64/ruby/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:281 vendor/rails/activesupport/lib/active_support/dependencies.rb:503:in `load'' vendor/rails/activesupport/lib/active_support/dependencies.rb:503:in `load'' vendor/rails/activesupport/lib/active_support/dependencies.rb:355:in `new_constants_in'' vendor/rails/activesupport/lib/active_support/dependencies.rb:503:in `load'' vendor/rails/railties/lib/commands/servers/mongrel.rb:64 /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'' /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'' vendor/rails/activesupport/lib/active_support/dependencies.rb:510:in `require'' vendor/rails/activesupport/lib/active_support/dependencies.rb:355:in `new_constants_in'' vendor/rails/activesupport/lib/active_support/dependencies.rb:510:in `require'' vendor/rails/railties/lib/commands/server.rb:39 /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'' /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'' script/server:3 This is my controller: class AuditTestsController < ApplicationController unloadable before_filter :find_project def index @audit_tests = AuditTest.find(:all) end def new @test_statuses = TestStatus.find(:all) @audit_test = AuditTest.new @audit_test.project = @project # <------- HERE I got the error render :layout => !request.xhr? end def create if @audit_test.save #attach_files(@issue, params[:attachments]) flash[:notice] = l(:notice_successful_create) #Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?(''issue_added'') redirect_to :action => ''index'' return end end def update end def destroy end def show end private def find_project @project = Project.find(params[:project_id]) end end And this is the view: <h2><%=l(:label_audit_test_plural)%></h2> <% html_title(l(:label_audit_test_plural)) %> <%= link_to l(:label_audit_test_new), :controller => "audit_tests", :action => "new", :project_id => @project %> <% if @audit_tests.empty? %> <p class="nodata"><%= l(:label_no_data) %></p> <% else %> <%= render :partial => ''audit_tests/list'', :locals => {:audit_tests => @audit_tests, :query => @query} %> <% end %> Project is something I not manage, is part of the main application, so I don''t know if it changes at runtime.
Eduardo Yáñez Parareda
2009-Oct-05 11:22 UTC
Re: AssociationTypeMismatch expected Project got Project
I realized it doesn''t happen in production environment ?¿
Frederick Cheung
2009-Oct-05 11:57 UTC
Re: AssociationTypeMismatch expected Project got Project
On Oct 5, 11:33 am, Eduardo Yáñez Parareda <eduardo.ya...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Using RAILS_GEM_VERSION = ''2.1.2'' > > Hello, I''m developing a plugin for another rails app. When I try to > show the new form view I got this error: > > ActiveRecord::AssociationTypeMismatch in Audit testsController#new > > Project(#70348727429120) expected, got Project(#70348730882020) >The root cause of your problem is that in development mode plugins are not reloaded between requests (at least that''s the default) but your application classes are, so if your plugin model class holds a reference to one of your model classes then from the second request that reference now points at an old version of the class (which isn''t equal to the fresh one, hence the slightly confusing message). One way around this is to have your plugin be reloaded on each request too, among other ways this can be done by removing it from ActiveSupport::Dependencies.load_once_paths (which was just Dependencies.load_once_paths in a previous version of rails - don''t remember when the switch happened( Fred
Eduardo Yáñez Parareda
2009-Oct-06 08:00 UTC
Re: AssociationTypeMismatch expected Project got Project
Thank you very much for that explanation. On Oct 5, 1:57 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Oct 5, 11:33 am, Eduardo Yáñez Parareda <eduardo.ya...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote:> Using RAILS_GEM_VERSION = ''2.1.2'' > > > Hello, I''m developing a plugin for another rails app. When I try to > > show the new form view I got this error: > > > ActiveRecord::AssociationTypeMismatch in Audit testsController#new > > > Project(#70348727429120) expected, got Project(#70348730882020) > > The root cause of your problem is that in development mode plugins > are not reloaded between requests (at least that''s the default) but > your application classes are, so if your plugin model class holds a > reference to one of your model classes then from the second request > that reference now points at an old version of the class (which isn''t > equal to the fresh one, hence the slightly confusing message). > One way around this is to have your plugin be reloaded on each request > too, among other ways this can be done by removing it from > ActiveSupport::Dependencies.load_once_paths (which was just > Dependencies.load_once_paths in a previous version of rails - don''t > remember when the switch happened( > > Fred