Closed ichilton closed 11 years ago
Where do you try use view helper? In rabl template?
@ichilton check this https://github.com/intridea/grape/wiki/Grape-and-Rails-Path-Helpers
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.
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.
Great, thanks!
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
??
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.
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