Created
May 8, 2012 18:06
-
-
Save zhubert/2638078 to your computer and use it in GitHub Desktop.
Batman deletion
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 BatmanRailsDemo.PostsController extends Batman.Controller | |
routingKey: 'posts' | |
index: (params) -> | |
BatmanRailsDemo.Post.load (err) -> throw err if err | |
@set 'posts', BatmanRailsDemo.Post.get('all') | |
@set 'post', new BatmanRailsDemo.Post() | |
show: (params) -> | |
@set 'post', BatmanRailsDemo.Post.find parseInt(params.id, 10), (err) -> | |
throw err if err | |
@render source: 'posts/show' | |
new: (params) -> | |
@set 'post', new BatmanRailsDemo.Post() | |
@form = @render() | |
create: (params) -> | |
@get('post').save (err) => | |
$('#new_post').attr('disabled', false) | |
if err | |
throw err unless err instanceof Batman.ErrorsSet | |
else | |
BatmanRailsDemo.flashSuccess "#{@get('post.title')} created successfully!" | |
@redirect '/posts' | |
edit: (params) -> | |
@set 'post', BatmanRailsDemo.Post.find parseInt(params.id, 10), (err) -> | |
throw err if err | |
@form = @render() | |
update: (params) -> | |
@get('post').save (err) => | |
$('#edit_post').attr('disabled', false) | |
if err | |
throw err unless err instanceof Batman.ErrorsSet | |
else | |
BatmanRailsDemo.flashSuccess "#{@get('post.title')} updated successfully!" | |
@redirect '/posts' | |
# not routable, an event | |
destroy: -> | |
@get('post').destroy (err) => | |
if err | |
throw err unless err instanceof Batman.ErrorsSet | |
else | |
BatmanRailsDemo.flashSuccess "Removed successfully!" | |
@redirect '/posts' |
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
batman console error via the throw, on Dropbox | |
http://db.tt/rYKeSwdk |
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 | |
respond_to :json | |
def index | |
respond_with Post.all | |
end | |
def show | |
respond_with Post.find(params[:id]) | |
end | |
def create | |
respond_with Post.create(params[:post]) | |
end | |
def update | |
respond_with Post.update(params[:id], params[:post]) | |
end | |
def destroy | |
@post = Post.find(params[:id]) | |
@post.destroy | |
respond_to do |format| | |
format.json { head :ok} | |
end | |
end | |
end |
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
log file: | |
Started DELETE "/posts/19.json" for 127.0.0.1 at 2012-05-08 10:53:04 -0700 | |
Processing by PostsController#destroy as JSON | |
Parameters: {"id"=>"19"} | |
Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT 1 [["id", "19"]] | |
(0.1ms) begin transaction | |
SQL (0.2ms) DELETE FROM "posts" WHERE "posts"."id" = ? [["id", 19]] | |
(2.0ms) commit transaction | |
Completed 200 OK in 5ms (ActiveRecord: 2.5ms) | |
all fine rails side |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
err.state is 'rejected'