Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

RABL with a basic ruby class #275

Closed
Altonymous opened this issue Jun 27, 2012 · 6 comments
Closed

RABL with a basic ruby class #275

Altonymous opened this issue Jun 27, 2012 · 6 comments
Labels

Comments

@Altonymous
Copy link

Unless I'm doing something wrong, this Tips & Tricks no longer seems to work.

https://github.com/nesquena/rabl/wiki/Tips-and-tricks

@databyte
Copy link
Collaborator

Are you referring to the latter part that I just added?

Here's a variation of a template from the integration suite:

object @post
cache @post

attributes :title, :body
attributes :created_at => :posted_at

node(:foo_helper) { helper_foo }

node(:post_object) do |post|
  [post.title, post.body]
end

child :user do
  attributes :username, :email, :location
end

glue :user do
  attributes :username => :author_name
end

code(:created_date) do |p|
  partial("posts/date", :object => p.created_at)
end
{"article"=>
     {"title"=>"Foo",
      "body"=>"Bar",
      "posted_at"=>"2012-06-27T16:22:24Z",
      "foo_helper"=>"FOO!",
      "post_object"=>["Foo", "Bar"],
      "user"=>{"username"=>"billybob", "email"=>"billy@bob.com", "location"=>"SF"},
      "author_name"=>"billybob",
      "created_date"=>{"day"=>27, "hour"=>16, "full"=>"2012-06-27T16:22:24Z"}}}

@Altonymous
Copy link
Author

I'm referring to the part where you create a basic ruby class

class MyClass
attr_accessor :id, :name
end

Then you try and do object false in the rabl template. It tries to call to_a and fails with undefined_method

@Altonymous
Copy link
Author

Here's a gist of what it would ideally be...

https://gist.github.com/3005300

I tried changing it around to use object false, but that doesn't seem to work

@databyte
Copy link
Collaborator

In your case, you have a valid object (@machines) and so it should work. I'll be back in an hour from lunch and I'll try it out.

@Altonymous
Copy link
Author

Nevermind it was a me issue. I wasn't requesting json... l-P Looks like it's time for me to take a lunch break too!

@databyte
Copy link
Collaborator

Awesome - I was going to say next is to verify that the template is being accessed and throwing a debugger call into the rabl file itself.

Glad it's working!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants