ruby-grape / grape-rabl

Use rabl with grape
MIT License
136 stars 29 forks source link

How would you construct rabl to render the correct version of the rabl view? #23

Closed rantrix closed 10 years ago

rantrix commented 10 years ago

If I have a user.rabl that is different for two different versions of the grape API, how do I get grape-rabl to render the correct one based on the grape api class setup?

Lets take this for an example:

File paths:

app/views/api/v1/user.rabl
app/views/api/v2/user.rabl

Grape API classes:

class API::V1::Users < Grape::API
  version 'v1', using: :header, vendor: 'me'
  format :json
  formatter :json, Grape::Formatter::Rabl
end

class API::V2::Users < Grape::API
  version 'v2', using: :header, vendor: 'me'
  format :json
  formatter :json, Grape::Formatter::Rabl
end

I have application.rb set up like so:

class Application < Rails::Application
  config.middleware.use(Rack::Config) do |env|
    env['api.tilt.root'] = Rails.root.join "app", "views", "api", 'v1'
    env['api.tilt.root'] = Rails.root.join "app", "views", "api", 'v2'
  end
end

Given this setup, rabl just renders v2 of user.rabl since it was the last one. I would appreciate any help. Thank you!