Skip to content

Instantly share code, notes, and snippets.

@lackac
Created May 19, 2011 17:47
Show Gist options
  • Save lackac/981323 to your computer and use it in GitHub Desktop.
Save lackac/981323 to your computer and use it in GitHub Desktop.
budapest.rb with @wycats

Notes of the talk:

http://trevmex.com/post/5639010531/building-rails-apps-for-the-rich-client

Skype log

# GET /api/bulk?posts=all
{
  posts: [
    {
     id: 1,
     title: "This is a post"
   }
  ]
}
# GET /api/bulk?posts=1,2
{
  posts: [
    {
     id: 1,
     title: "This is a post"
   },
    {
     id: 2,
     title: "Another post"
   }
  ]
}
# POST /api/bulk
{
  posts: [
    { title: "This is a post" },
    { title: "Another post" }
  ]
}
# PUT /api/bulk
{
  posts: [
    {
     id: 1,
     title: "This is a post"
   },
    {
     id: 2,
     title: "Another post"
   }
  ]
}
# POST /api/bulk
{
  posts: [
    { title: "This is a post" },
    { title: "Another post" }
  ]
}

# becomes:

Post.create(title: "This is a post")
Post.create(title: "Another post")

class ApplicationResource < Bulk::Resource
  def authenticate(method)
    # do devise stufff
  end
   
  def authorize(method)
    user.admin?
  end
end

class PostsResource < Bulk::Resource
 delegate :current_user, to: 'controller'

  def authorize_record(action, record)
    current_user.can?(action, record)
  end
 
  def create(hashes)
    # custom create code for posts
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment