Recommended rdf usage in Ruby on Rails
I'd like to publish rdf in my rails apps. What's the right way t开发者_开发百科o do it?
(For people who are interested in working with actual RDF data, please see The State of RDF in Ruby.)
The short answer to your question: You're looking for respond_to. In general, you'd write something like:
class PeopleController < ApplicationController::Base
respond_to :html, :rdf
def index
@people = Person.all
respond_to do |format|
format.html
format.rdf { convert_to_rdf(@people) }
end
end
end
Of course, you'll have to write 'convert_to_rdf'. You might find that RDF.rb is helpful for that.
Have you tried ActiveRDF? Quoting:
ActiveRDF is a library for accessing RDF data from Ruby programs. It can be used as data layer in Ruby-on-Rails, similar to ActiveRecord (which provides an O/R mapping to relational databases). ActiveRDF in RoR allows you to create semantic web applications very rapidly. ActiveRDF gives you a Domain Specific Language (DSL) for your RDF model: you can address RDF resources, classes, properties, etc. programmatically, without queries.
- ActiveRDF can be used with various RDF stores, adapters to other stores can be written very easily.
- ActiveRDF uses convention over configuration, which means it works very nicely in 90% of the cases.
- ActiveRDF is open source, released under the LGPL license.
For those looking at this issue in the future: the gem rdf-serializers uses active_model_serializers to easily serialize to RDF.
精彩评论