ruby-grape / grape-rabl

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

View Helpers #9

Closed ichilton closed 11 years ago

ichilton commented 11 years ago

It doesn't seem to be possible to use view helpers like article_path.

I get: undefined method `article_path' for #Rabl::Engine:0x000000084a4bd0

Thanks,

Ian

LTe commented 11 years ago

Where do you try use view helper? In rabl template?

LTe commented 11 years ago

@ichilton check this https://github.com/intridea/grape/wiki/Grape-and-Rails-Path-Helpers

lucaspiller commented 11 years ago

Hey, I'm having the same issue. I've setup Grape within a Rails app but can't use the helpers in the Rabl views.

Including the helper in the endpoint as per the wiki article doesn't expose it to Rabl.

LTe commented 11 years ago

I added specs for custom helpers. Try this:

class API < Grape::API
  helpers Rails.application.routes.url_helpers
end

Please re-open in case of any problems.

@lucaspiller @ichilton sorry it took so long.

ichilton commented 11 years ago

Great, thanks!

guilherme commented 10 years ago

this only works for the case of rendering inside grape, by accessing an endpoint. there's a way to do this using the:

 Rabl::Renderer.new(path_to_rabl, collection, :view_path => 'app/api/views', :format => 'hash').render

??

guilherme commented 10 years ago

i did it in a bizarre way, but works:

module ApplicationHelper

  def render_rabl_hash(view)
    engine = ::Tilt.new("app/api/views/%s.rabl" % view,  { :view_path => 'app/api/views', :format => 'hash' })
    engine.render(self)
  end

# ...
end

i needed because i wanted to get the "current_user".. and the first bootstrap from the application is rendered locally instead of getting via the grape api.