Skip to content

Instantly share code, notes, and snippets.

@zhubert
Created May 8, 2012 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhubert/2638078 to your computer and use it in GitHub Desktop.
Save zhubert/2638078 to your computer and use it in GitHub Desktop.
Batman deletion
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'
batman console error via the throw, on Dropbox
http://db.tt/rYKeSwdk
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
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
@zhubert
Copy link
Author

zhubert commented May 8, 2012

err.state is 'rejected'

@zhubert
Copy link
Author

zhubert commented May 8, 2012

For posterity, check out the repo for the answer

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