I'd like to publish rdf in my rails apps. What's the right way to do it?
-
Sorry, after reading first answer I think I put it wrong. My initial aim is just to generate rdf information in views from ActiveRecord. I don't want to use external rdf sources at this stage. For example, in a webpage devoted to a book I would like to include information about its title, author, publishing house, etc. – helcim Sep 14 '10 at 07:37
3 Answers
(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.

- 1,316
- 15
- 28
-
If you don't get a satisfactory answer, you might want to try post youy question to semanticoverflow.com (the parochial version of this). – badroit Sep 16 '10 at 00:37
For those looking at this issue in the future: the gem rdf-serializers uses active_model_serializers to easily serialize to RDF.

- 11
- 2