# AssociationTypeMismatch expected Project got Project

**URL:** <https://www.ruby-forum.com/t/associationtypemismatch-expected-project-got-project/176718>\
**Category:** Rails\
**Created:** [October 5, 2009, 12:34pm UTC](https://www.ruby-forum.com/t/associationtypemismatch-expected-project-got-project/176718 "2009-10-05T12:34:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![eyp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e274bd/32.png) [@eyp](https://www.ruby-forum.com/u/eyp)\
**Post date:** [October 5, 2009, 12:34pm UTC](https://www.ruby-forum.com/t/associationtypemismatch-expected-project-got-project/176718/1 "2009-10-05T12:34:36Z")

</div>

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:

## \<%=l(:label\_audit\_test\_plural)%\>
\<% 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? %\>

\<%= l(:label\_no\_data) %\>

\<% 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.

---

<div class="post-metadata">

**Author:** ![eyp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e274bd/32.png) [@eyp](https://www.ruby-forum.com/u/eyp)\
**Post date:** [October 5, 2009, 1:24pm UTC](https://www.ruby-forum.com/t/associationtypemismatch-expected-project-got-project/176718/2 "2009-10-05T13:24:22Z")

</div>

I realized it doesn’t happen in production environment ?¿

---

<div class="post-metadata">

**Author:** ![eyp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e274bd/32.png) [@eyp](https://www.ruby-forum.com/u/eyp)\
**Post date:** [October 5, 2009, 1:58pm UTC](https://www.ruby-forum.com/t/associationtypemismatch-expected-project-got-project/176718/3 "2009-10-05T13:58:55Z")

</div>

On Oct 5, 11:33 am, Eduardo Yáñez Parareda [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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

---

<div class="post-metadata">

**Author:** ![eyp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e274bd/32.png) [@eyp](https://www.ruby-forum.com/u/eyp)\
**Post date:** [October 6, 2009, 10:01am UTC](https://www.ruby-forum.com/t/associationtypemismatch-expected-project-got-project/176718/4 "2009-10-06T10:01:27Z")

</div>

Thank you very much for that explanation.

On Oct 5, 1:57 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
