Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

NoMethodError - undefined method `rabl' for #<Sinatra::Application:0x701f48> #332

Closed
melriffe opened this Issue · 13 comments

7 participants

@melriffe

I'm wondering if the newer versions of Sinatra broke RABL integration.

Gem Versions:

  • rabl (0.7.2)
  • sinatra (1.3.3)

Doesn't Work

get '/' do
  @foo = {:greeting => "Ka-Blam!"}
  rabl :foo
end

Works

get '/' do
  @foo = {:greeting => "Ka-Blam!"}
  render :rabl, :foo, :format => :json
end

I was prototyping RABL support in my Sinatra app. I wanted to use the rabl version so I can support JSON or XML. I want to use the provides [:json, :xml] construct.

@nesquena
Owner

What error do you get when you try:

get '/' do
  @foo = {:greeting => "Ka-Blam!"}
  rabl :foo
end

That part is built into Sinatra itself: https://github.com/sinatra/sinatra/blob/master/lib/sinatra/base.rb#L657

@melriffe
NoMethodError at /
undefined method `rabl' for #<Sinatra::Application:0x5f0bb8>

    file: desert_inn.rb
    location: block in <main>
    line: 37

Because I'm new to Sintara, to my untrained eye it looks like this piece of code didn't work as expected:

Tilt.register 'rabl', RablTemplate
@nesquena
Owner

If this works:

render :rabl, :foo, :format => :json

then tilt is properly registered. This must be something else with Sinatra, I will poke around when I get a chance /cc @jc00ke

For reference, original pull request: sinatra/sinatra#521

@melriffe

Cheers! If there's anything you'd like to me try, just let me know.

@jc00ke

@melriffe what does the foo template look like? Just curious.

@melriffe

@jc00ke no worries:

object @foo
attributes :greeting
@databyte
Collaborator

Any news?

@databyte databyte closed this
@colinrymer

Still an issue.

get '/' do
  @foo = {:greeting => "Ka-Blam!"}
  rabl :foo
end

still returns undefined method 'rabl'

@databyte
Collaborator
@colinrymer

The render ... hack still works to fix it.

@databyte
Collaborator

Houston, we have a problem. Tracing it back, Sinatra v1.3.3 does not have a rabl call.

I guess it stays closed with a note to look forward to Sinatra v1.3.4.

I have no insight on that release schedule.

@oogali

In the meantime, until it's merged into Sinatra, you can get the same functionality by manually defining your own helper (using the code from the pull request).

helpers do
  ...
  def rabl(template, options = {}, locals = {})
    Rabl.register!
    render :rabl, template, options, locals
  end
end
@philostler

Just hit this myself. I'm also defining the helper myself for the time being.

Helper is in the master but hasn't made it across to the 1.3.x branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.