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:inreplace’
vendor/rails/activerecord/lib/active_record/associations.rb:1114:in
project=' vendor/plugins/redmine_audit_tests/app/controllers/ audit_tests_controller.rb:13:innew’
vendor/rails/actionpack/lib/action_controller/base.rb:1166:in send' vendor/rails/actionpack/lib/action_controller/base.rb:1166:inperform_action_without_filters’
vendor/rails/actionpack/lib/action_controller/filters.rb:579:in
call_filters' vendor/rails/actionpack/lib/action_controller/filters.rb:572:inperform_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:inmeasure’
vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in
perform_action_without_rescue' vendor/rails/actionpack/lib/action_controller/rescue.rb:201:inperform_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:incache’
vendor/rails/activerecord/lib/active_record/query_cache.rb:8:in
cache' vendor/rails/actionpack/lib/action_controller/caching/sql_cache.rb: 12:inperform_action’
vendor/rails/actionpack/lib/action_controller/base.rb:529:in send' vendor/rails/actionpack/lib/action_controller/base.rb:529:inprocess_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:inprocess’
vendor/rails/actionpack/lib/action_controller/base.rb:389:in process' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:149:inhandle_request’
vendor/rails/actionpack/lib/action_controller/dispatcher.rb:107:in
dispatch' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:104:insynchronize’
vendor/rails/actionpack/lib/action_controller/dispatcher.rb:104:in
dispatch' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:120:indispatch_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:inprocess’
/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:inprocess’
/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:ineach’
/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:inrun’
/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:innew’
/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:ininitialize’
/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:inrun’
/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:ineach’
/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:inrun’
/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:inload’
vendor/rails/activesupport/lib/active_support/dependencies.rb:503:in
load' vendor/rails/activesupport/lib/active_support/dependencies.rb:355:innew_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:ingem_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:inrequire’
vendor/rails/activesupport/lib/active_support/dependencies.rb:355:in
new_constants_in' vendor/rails/activesupport/lib/active_support/dependencies.rb:510:inrequire’
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:inrequire’
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:inreplace’
vendor/rails/activerecord/lib/active_record/associations.rb:1114:in
project=' vendor/plugins/redmine_audit_tests/app/controllers/ audit_tests_controller.rb:13:innew’
vendor/rails/actionpack/lib/action_controller/base.rb:1166:in send' vendor/rails/actionpack/lib/action_controller/base.rb:1166:inperform_action_without_filters’
vendor/rails/actionpack/lib/action_controller/filters.rb:579:in
call_filters' vendor/rails/actionpack/lib/action_controller/filters.rb:572:inperform_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:inmeasure’
vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in
perform_action_without_rescue' vendor/rails/actionpack/lib/action_controller/rescue.rb:201:inperform_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:incache’
vendor/rails/activerecord/lib/active_record/query_cache.rb:8:in
cache' vendor/rails/actionpack/lib/action_controller/caching/sql_cache.rb: 12:inperform_action’
vendor/rails/actionpack/lib/action_controller/base.rb:529:in send' vendor/rails/actionpack/lib/action_controller/base.rb:529:inprocess_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:inprocess’
vendor/rails/actionpack/lib/action_controller/base.rb:389:in process' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:149:inhandle_request’
vendor/rails/actionpack/lib/action_controller/dispatcher.rb:107:in
dispatch' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:104:insynchronize’
vendor/rails/actionpack/lib/action_controller/dispatcher.rb:104:in
dispatch' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:120:indispatch_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:inprocess’
/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:inprocess’
/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:ineach’
/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:inrun’
/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:innew’
/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:ininitialize’
/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:inrun’
/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:ineach’
/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:inrun’
/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:inload’
vendor/rails/activesupport/lib/active_support/dependencies.rb:503:in
load' vendor/rails/activesupport/lib/active_support/dependencies.rb:355:innew_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:ingem_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:inrequire’
vendor/rails/activesupport/lib/active_support/dependencies.rb:355:in
new_constants_in' vendor/rails/activesupport/lib/active_support/dependencies.rb:510:inrequire’
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:inrequire’
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.

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

On Oct 5, 11:33 am, Eduardo Yáñez Parareda [email protected]
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

Thank you very much for that explanation.

On Oct 5, 1:57 pm, Frederick C. [email protected]