Created
October 17, 2010 11:06
-
-
Save amrnt/630755 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
var Post, app; | |
Post = Model("post", { | |
persistence: Model.REST("/posts") | |
}); | |
app = $.sammy(function() { | |
this.element_selector = '#body'; | |
this.get('#!/', function(context) { | |
var posts; | |
posts = Post.all(); | |
return context.log(posts); | |
}); | |
this.get('#!/posts/:id', function(context) { | |
var post; | |
post = Post.find(this.params.id); | |
return context.log(post); | |
}); | |
this.post('#!/posts', function(context) { | |
var post; | |
post = new Post({ | |
title: "stuff" | |
}); | |
return post.save(); | |
}); | |
return true; | |
}); | |
$(function() { | |
return app.run('#!/'); | |
}); | |
return true; | |
})(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PostsController < ApplicationController | |
def index | |
@posts = Post.all | |
render :json => @posts | |
end | |
def show | |
@post = Post.find(params[:id]) | |
render :json => @post | |
end | |
def create | |
@post = Post.new(params[:post]) | |
if @post.save | |
render :json => @post, :status => :created, :location => @post | |
else | |
render :json => @post.errors, :status => :unprocessable_entity | |
end | |
end | |
def update | |
@post = Post.find(params[:id]) | |
if @post.update_attributes(params[:post]) | |
head :ok | |
else | |
render :json => @post.errors, :status => :unprocessable_entity | |
end | |
end | |
def destroy | |
@post = Post.find(params[:id]) | |
@post.destroy | |
head :ok | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment