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

Already on GitHub? Sign in to your account

Cannot alias collection attribute #283

Closed
centaure opened this Issue Jul 9, 2012 · 4 comments

Comments

Projects
None yet
2 participants

centaure commented Jul 9, 2012

My Rabl file was:

collection @tags
attributes :id, :name

The above worked fine. For example, running curl gave me:

centaur@ubuntu:~$ curl http://localhost:3000/api/videos/1/tags.json
[{"name":"bat2","id":1}]

However, when I attempted to alias the second attribute, as shown below, it does not return me the attribute I attempted to alias:

collection @tags
attributes :id, :name => :foo

centaur@ubuntu:~$ curl http://localhost:3000/api/videos/1/tags.json
[{"id":1}]

And if I move the aliased attribute to be the first as shown below, I get a bunch of errors thrown (errors are attached at the end of this mail):

collection @tags
attributes :name => :foo, :id

What am i doing wrong here?

(note the following is just the beginning of the error trace).

centaur@ubuntu:~$ curl http://localhost:3000/api/videos/1/tags.json

<title>Action Controller: Exception caught</title> <style> body { background-color: #fff; color: #333; }
body, p, ol, ul, td {
  font-family: helvetica, verdana, arial, sans-serif;
  font-size:   13px;
  line-height: 18px;
}

pre {
  background-color: #eee;
  padding: 10px;
  font-size: 11px;
}

a { color: #000; }
a:visited { color: #666; }
a:hover { color: #fff; background-color:#000; }
</style>

SyntaxError in Videos#tags

Showing /home/centaur/Documents/fungus_mock1/fungus/fungus/copper/app/views/videos/tags.json.rabl where line #1 raised:

(eval):2:in `render': compile error
(eval):2: syntax error, unexpected '\n', expecting tASSOC

Extracted source (around line #1):

1: collection @tags
2:   attributes :name => :foo, :id

centaure commented Jul 9, 2012

I have the same problem when I deal with a model. The following will not return me the second attribute (:tag_name_id) if I attempt to alias it as "attributes :name, :tag_name_id => :id".

object @tag

attributes :name, :tag_name_id

Collaborator

databyte commented Jul 9, 2012

Aliased hashes have to go on a separate line. This will work:

collection @tags

attributes :id, :something_else
attributes :name => :foo

centaure commented Jul 9, 2012

Thanks databyte, that works!

Maybe it would be a good idea to clarify this in the documentation (https://github.com/nesquena/rabl#attributes).

So aliasing both attributes within one "attributes" method call (i.e. "attributes id: => :foo_id, :name => :foo"), works (just like in the documentation example above "attributes :bar => :baz, :dog => :animal"). But having one aliased attribute + one non-aliased attribute within one "attributes" method call throws errors (e.g. "attributes :bar => :baz, :dog") . This is not clarified in https://github.com/nesquena/rabl#attributes, and I spent a couple of hrs debugging this to no avail.

Thanks a lot for the help databyte!

Collaborator

databyte commented Jul 11, 2012

Done - thanks.

@databyte databyte closed this Jul 11, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment