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

changeset not work #446

Closed
piya23300 opened this issue Dec 11, 2014 · 8 comments
Closed

changeset not work #446

piya23300 opened this issue Dec 11, 2014 · 8 comments

Comments

@piya23300
Copy link

I use rails 4.1.8 , paper_trail 3.0.6

event = 'update'
object_changes = "--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess\nstatus_id:\n- 1\n- 2\n"
when I call object.versions.last.changeset, it returns {}

Cloud you help me?

@batter
Copy link
Collaborator

batter commented Dec 11, 2014

What happens if you load up a console and run PaperTrail.serializer.load(object_changes)?

If you get a return value from that beyond {}, then here is the codeblock it tries to execute when you invoke changeset. So there is likely some sort of error being raised within that block that is getting rescued.

@piya23300
Copy link
Author

object_change : "--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess\nstatus_id:\n- 6\n- 8\n"

I run PaperTrail.serializer.load(object_changes) it works and returns {"status_id"=>[6, 8]}

I run

@changeset ||= HashWithIndifferentAccess.new(_changes).tap do |changes|
   item_type.constantize.unserialize_attribute_changes(changes)
end

it works and returns {"status_id"=>[6, 8]}

and last
I run version_object.changeset then return {}
Why it is getting rescued?

@batter
Copy link
Collaborator

batter commented Dec 11, 2014

It's hard to say what exactly the issue is with this data. I would recommend running gem which paper_trail, finding the source location, and then going and editing lib/paper_trail/version_concern.rb and commenting out the rescue statement portion of that method, and then re-running the changeset method and checking the stack trace.

@piya23300
Copy link
Author

Thank you,
If it tests it, I will tell you.

@batter
Copy link
Collaborator

batter commented Dec 29, 2014

@piya23300 - did you give that a try?

@piya23300
Copy link
Author

@batter Thank you to alert me haha I forgot it ^^

I tests it, I found error

NameError: undefined local variable or method `version_class_name' for #<Class:0x007f8152ceb578>

I think because my class use STI

AAA::BBB::CCC class that use paper_trail
but object.versions.last.item_type = AAA::BBB
AAA::BBB class doesn't want use paper_trail
this reason of error

and then
I updated item_type from "AAA::BBB" to "AAA::BBB::CCC"
object.versions.last.update(item_type: "AAA::BBB::CCC")

object.versions.last.changeset it work!

I try to fix it , I found cause from belongs_to :item, :polymorphic => true
http://stackoverflow.com/questions/21886440/combine-sti-and-polymorphic-with-rails-4

When I new version object object.versions.new
item_type alway sets self.class.base_class.name ("AAA::BBB")

I can't solve it.
Cloud you help me? please....

@batter
Copy link
Collaborator

batter commented Jan 16, 2015

Does #362 help you at all? I'll have to take a closer look at this and try to generate a test case. If you can provide a dummy app or PR w/ failing tests that would help a lot.

@batter
Copy link
Collaborator

batter commented Feb 3, 2015

This is a dup of #404, closed in favor of that one, clearly there is an issue when PaperTrail is used in conjunction with STI that needs to be addressed.

@batter batter closed this as completed Feb 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants