I've posted a question relating to this before but it was unclear. I've simplified the code so I can copy it here and have it be as straightforward as possible. I'm still not sure what the best way to debug this may be but here it goes:
My 'new' action (could be any really) for a resource (again, can be any):
def new
RDF::RDFa::Reader.open("http://www.tripadvisor.com/Hotel_Review-g186525-d280839-Reviews-Gerald_s_Place-Edinburgh_Scotland.html") do |r|
r.each_statement do |statement|
Rails.logger.debug(statement)
end
end
respond_to do |format|
format.html { }# new.html.haml
format.json { render json: @base_item }
format.js
end
end
The page renders fine and the RDF code is run successfully, however, when I re开发者_JAVA技巧fresh the page or try to access anything else, I get the following (substitude 'base_item' with whatever resource I'm trying to access, they all fail with this error):
ActionController::RoutingError (private method `redefine_method' called for #<Class:0x000001058527c0>):
app/models/base_item.rb:3:in `<class:BaseItem>'
app/models/base_item.rb:2:in `<top (required)>'
app/controllers/base_items_controller.rb:3:in `<top (required)>'
I'm wondering if this is something specific to the rdf gem (which uses nokogiri) or if it is a general routing issue but haven't found a way to test that.
Any help appreciated.
EDIT: It seems it has to do with the r.each_statement line as if I take that out, things keep working..
UPDATE: I haven't been able to reproduce this outside of Rails but I've narrowed it down to an issue with ActiveRecord. I've set up a sample app at https://github.com/slamorsi/rdfTest
There are two models, Test and TestChild. The error is reproducible if Test and TestChild are related - right now Test has a has_many relationship with TestChild. The root of the app goes to test#index which has sample RDF/RDFa code. If you load the page once then refresh, you'll see the 'redefine method called...' error. If there's no relationship between the models or if no RDF/RDFa statements.each code is executed, everything works fine. I don't know what could possibly cause this.
The RDF gem doesn't use Nokogiri, but the RDF::RDFa gem does. You could try to run this with a Turtle input file, for example, and see if you get the same results.
Queryable#each_statement does use an iterator, but I don't see how this could infect the context your running in. You might look to see if any new methods have been defined on @base_item. It may be that some of the RDF classes are defining methods that interfere with Rails, which would be a bug.
If you can make a short example, I can look at it further. Submit an issue to http://github.com/gkellogg/rdf/issues (if it isn't RDF::RDFa specific), or rdf-rdfa/issues otherwise.
精彩评论