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

Green shoes seems to conflict with ActiveRecord models #56

Open
translunar opened this issue Nov 16, 2011 · 2 comments
Open

Green shoes seems to conflict with ActiveRecord models #56

translunar opened this issue Nov 16, 2011 · 2 comments

Comments

@translunar
Copy link
Contributor

I'm trying to use SciRuby::Plotter (a Green Shoes GUI) with Rails 3.1.1. I have a method on one of my models called update!, which sends an HTTP request to get some meta info, and then applies that meta info to the object (and saves). This happens within a transaction.

(1.0ms)  BEGIN
(1.3ms)  SELECT 1 FROM "genes" WHERE ("genes"."entrez_id" = 54101 AND "genes"."id" != 177592) LIMIT 1
(24.8ms)  UPDATE "genes" SET "symbol" = 'RIPK4', "name" = 'receptor-interacting serine-threonine kinase 4', "desc" = 'The protein encoded by this gene is a serine/threonine protein kinase that interacts with protein kinase C-delta. The encoded protein can also activate NFkappaB and is required for keratinocyte differentiation. This kinase undergoes autophosphorylation. [provided by RefSeq, Jul 2008]', "updated_at" = '2011-11-16 23:20:46.130810' WHERE "genes"."id" = 177592
(1.2ms)  COMMIT
NOTICE:  there is no transaction in progress
(1.1ms)  ROLLBACK
NoMethodError: undefined method `clear' for #<Gene:0xf954c28>
from /usr/local/lib/ruby/gems/1.9.1/gems/activemodel-3.1.1/lib/active_model/attribute_methods.rb:385:in `method_missing'
from /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/attribute_methods.rb:60:in `method_missing'
from /usr/local/lib/ruby/gems/1.9.1/gems/green_shoes-1.0.309/lib/shoes/ruby.rb:155:in `each'
from /usr/local/lib/ruby/gems/1.9.1/gems/green_shoes-1.0.309/lib/shoes/ruby.rb:155:in `clear'
from /usr/local/lib/ruby/gems/1.9.1/gems/green_shoes-1.0.309/lib/shoes/ruby.rb:155:in `each'
from /usr/local/lib/ruby/gems/1.9.1/gems/green_shoes-1.0.309/lib/shoes/ruby.rb:155:in `clear'
from /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:374:in `rollback_transaction_records'
from /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:230:in `rescue in transaction'

I think there must be a conflict between lib/shoes/ruby.rb's Array modification and ActiveRecord.

I will try to gather some more data.

@translunar
Copy link
Contributor Author

So it looks like ActiveRecord expects clear on Array to work differently. I was able to get rid of the aforementioned problem simply by renaming, in lib/shoes/ruby.rb, def clear to def green_shoes_clear, and def clear_all to def green_shoes_clear_all.

Of course, the problem with that solution is that now no Shoes app shows up at all. Not ideal.

@ashbb
Copy link
Owner

ashbb commented Nov 17, 2011

Hi John,

Thank you for the very helpful information!
I should have had more consideration for overwriting Array#clear method. xx-P

This is a patch. Try it out.

class Array
  alias :_clear :clear
  def clear
    self.each{|e| e.clear if e.class.method_defined? :clear}
    _clear
  end
end

And... you have taught me another bug involved.
Look at this commit: 2e50b7c

ashbb

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