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

Documentation for Rails? #6

Open
no-reply opened this issue Feb 4, 2017 · 4 comments
Open

Documentation for Rails? #6

no-reply opened this issue Feb 4, 2017 · 4 comments
Assignees

Comments

@no-reply
Copy link
Member

no-reply commented Feb 4, 2017

The README.md says using this with Rails should look like:

# config/application.rb
require 'rack/linkeddata'

class Application < Rails::Application
  config.middleware.use Rack::LinkedData::ContentNegotiation
end

This works fine to get the middleware into the Rails stack, but it's not at all clear what to do from there. Returning an RDF::Enumerable from a controller action doesn't do the trick, and I can't find any good recommendations about how to give an arbitrary object as a response body. Is there a right way to do this we can get into the README?

@gkellogg
Copy link
Member

gkellogg commented Feb 4, 2017

Returning Enumerable from a controller should kick in content-negotiation to get the appropriate form. This is used (through sinatra-linked data) in the Linter, for example. SPARQL has a similar mechanism for doing content negotiation.

Certainly the README could use improvement, and this probably isn't a common way for Rails developers to do content negotiation. Specs should describe how it's done in rack-linkeddata, though.

Contributions welcome.

@no-reply
Copy link
Member Author

no-reply commented Feb 4, 2017

When returning an enumerable from e.g. MyController#index, I get an ActionView::MissingTemplate error.

Several other things I've tried (e.g. response.body = RDF::Graph.new and return) fail in other ways.

@no-reply
Copy link
Member Author

no-reply commented Feb 4, 2017

I'm able to hack around the ActionView issue by adding an empty index.erb template, but then the best result I've been able to achieve is getting an ntriples string to appear in an ActionDispatch::Response::RackBody#body. (this is with response.body = my_graph).

Returning an Enumerable leads to an empty response body; but I haven't been able to spot where the enumerable disappears.

@gkellogg
Copy link
Member

gkellogg commented Feb 4, 2017

It's possible that Rails has changed enough since this was introduced that it either needs to be modified, or is no longer relevant for use with Rails.

A more natural way in Rails is to use respond_to {} for the mime types you're interested in and use Enumerable#dump with the appropriate format.

I use this in the context of Sinatra, where things may be a bit simpler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants