/
README
55 lines (43 loc) · 1.4 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Jester ported to mootools
Result or syntax may vary
But the code's much better
var Post = new Resource("Post")
Post.find("all", function(p) {
p.title = "All your base are belong to us"
p.save
})
p = new Post({title: "Hello world"}).save
p.errors #=> {something}
This thing is rails & merb-oriented
As they are supported out of the box:
Merb, with Merb.disable(:json) & ActiveRecord:
provides :json
display @post, :only => [:title, :body, :created_at, :id], :include => {:comments => {:only => [:body, :created_at, :id]}}
Merb without ActiveRecord:
provides :json
display @post #cant control anything here, associations not included
Rails:
respond_to do |f|
f.json do
@post.to_json, :only => [:title, :body, :created_at, :id], :include => {:comments => {:only => [:body, :created_at, :id]}}
end
end
So with that backend we can do this:
new Resource("Post", {
associations: {
comments: ["Comment", {prefix: true}] #setting autoprefix on
}
})
Post.find(1).chain(function(post) {
post.title = "defaced"
post.comments.each(function(comment) {
comment.destroy() # DELETE /posts/1/comments/n
})
post.save().chain(function(result) {
if (!result) {
alert(post.errors) # => ["Title is too short"]
} else {
alert("Ha ha ha... You are on your way to destruction")
}
}) # PUT /posts/1/ title=defaced
})