Using Rails Path Helpers in Draper Decorators with Grape

elado edited this page Dec 27, 2012 · 1 revision

In order to have path helpers available in draper helper (h), add the following code to an initializer (config/initializers/draper.rb):

module Draper
  class HelperProxy
    include Rails.application.routes.url_helpers
    default_url_options[:host] = ::Rails.application.routes.default_url_options[:host]
  end
end

and under config/environments/development.rb and all other environment files, add

routes.default_url_options = { host: "local.dev.com", port: 3000 }

To mix Rails, Draper, Rabl and Grape together, see also https://github.com/nesquena/rabl/wiki/Using-Rabl-with-Grape

And add to your Grape module:

represent Draper::Decorator, with: RablPresenter
represent Draper::CollectionDecorator, with: RablPresenter