Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssociationTypeMismatch #13

Open
xampo848 opened this issue Sep 14, 2016 · 2 comments
Open

AssociationTypeMismatch #13

xampo848 opened this issue Sep 14, 2016 · 2 comments
Labels

Comments

@xampo848
Copy link

xampo848 commented Sep 14, 2016

Hello, I just set this gem in my project but i got this error:
ActiveRecord::AssociationTypeMismatch (Employee(#70255204106080) expected, got User(#70255256449680)) when i try to update an employee.

I have a Employee model that is my "model_stamper" and an User model too.
I want to use Employee for being the model_stamper and only use it for track when the current_employee update another employee.
I don't know what could be happening.
without this gem, it works well. but I want to use it.
I appreciate it if someone could help.
rails version Rails 4.2.4
ruby 2.2.2

# initializers/activerecord_userstamp.rb
ActiveRecord::Userstamp.configure do |config|
   config.default_stamper = 'Employee'
   #config.creator_attribute = nil
   config.updater_attribute = :updated_by
   config.deleter_attribute = nil
end
activerecord (4.2.4) lib/active_record/associations/association.rb:218:in `raise_on_type_mismatch!'
activerecord (4.2.4) lib/active_record/associations/belongs_to_association.rb:12:in `replace'
activerecord (4.2.4) lib/active_record/associations/singular_association.rb:17:in `writer'
activerecord (4.2.4) lib/active_record/associations/builder/association.rb:123:in `updated_by='
activerecord-userstamp (3.0.4) lib/active_record/userstamp/utilities.rb:53:in `assign_attribute'
activerecord-userstamp (3.0.4) lib/active_record/userstamp/stampable.rb:113:in `set_updater_attribute'
activesupport (4.2.4) lib/active_support/callbacks.rb:432:in `block in make_lambda'
activesupport (4.2.4) lib/active_support/callbacks.rb:145:in `call'
activesupport (4.2.4) lib/active_support/callbacks.rb:145:in `block in halting_and_conditional'
activesupport (4.2.4) lib/active_support/callbacks.rb:504:in `call'
activesupport (4.2.4) lib/active_support/callbacks.rb:504:in `block in call'
activesupport (4.2.4) lib/active_support/callbacks.rb:504:in `each'
activesupport (4.2.4) lib/active_support/callbacks.rb:504:in `call'
activesupport (4.2.4) lib/active_support/callbacks.rb:92:in `__run_callbacks__'
activesupport (4.2.4) lib/active_support/callbacks.rb:778:in `_run_validation_callbacks'
activemodel (4.2.4) lib/active_model/validations/callbacks.rb:113:in `run_validations!'
activemodel (4.2.4) lib/active_model/validations.rb:337:in `valid?'
activerecord (4.2.4) lib/active_record/validations.rb:58:in `valid?'
activerecord (4.2.4) lib/active_record/validations.rb:83:in `perform_validations'
activerecord (4.2.4) lib/active_record/validations.rb:37:in `save'
activerecord (4.2.4) lib/active_record/attribute_methods/dirty.rb:21:in `save'
activerecord (4.2.4) lib/active_record/transactions.rb:286:in `block (2 levels) in save'
activerecord (4.2.4) lib/active_record/transactions.rb:351:in `block in with_transaction_returning_status'
activerecord (4.2.4) lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `transaction'
activerecord (4.2.4) lib/active_record/transactions.rb:220:in `transaction'
activerecord (4.2.4) lib/active_record/transactions.rb:348:in `with_transaction_returning_status'
activerecord (4.2.4) lib/active_record/transactions.rb:286:in `block in save'
activerecord (4.2.4) lib/active_record/transactions.rb:301:in `rollback_active_record_state!'
activerecord (4.2.4) lib/active_record/transactions.rb:285:in `save'
activerecord (4.2.4) lib/active_record/persistence.rb:252:in `block in update'
activerecord (4.2.4) lib/active_record/transactions.rb:351:in `block in with_transaction_returning_status'
activerecord (4.2.4) lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
activerecord (4.2.4) lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'
activerecord (4.2.4) lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
activerecord (4.2.4) lib/active_record/transactions.rb:220:in `transaction'
activerecord (4.2.4) lib/active_record/transactions.rb:348:in `with_transaction_returning_status'
activerecord (4.2.4) lib/active_record/persistence.rb:250:in `update'
draper (1.4.0) lib/draper/delegation.rb:10:in `update'
@lowjoel
Copy link
Owner

lowjoel commented Sep 17, 2016

What is the name of the class you're trying to save?

What is ActiveRecord::Userstamp.config.default_stamper_class.stamper within the controller action you're saving the record?

@xavierledoux
Copy link

xavierledoux commented Dec 11, 2017

Hi,

I'm running the same issue here.

undefined local variable or method `current_user' for #DashboardController:0x007f8ca05a60c0 Did you mean? current_employee

ruby '2.3.0'
gem 'rails', '4.2.3'

activerecord_userstamp.rb
ActiveRecord::Userstamp.configure do |config| config.default_stamper = 'Employee' config.creator_attribute = :creator_id config.updater_attribute = :updater_id config.deleter_attribute = nil end

employee.rb
model_stamper

country.rb
stampable

Any clue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants