Convenient functionality for actionpack.
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.gitignore
LICENSE
README.md
Rakefile
convenient-actionpack.gemspec

README.md

convenient-actionpack

Under construction... Watch your head.

Making common things easier for ActionController, etc.

Setup

In your Rails 3.1+ project, add this to your Gemfile:

gem 'convenient-actionpack', :git => 'git://github.com/garysweaver/convenient-actionpack.git'

Then run:

bundle install

Usage

Provides a wrap method to rescue StandardError to return an informative JSON error from JSON services instead of HTML when there is an error:

def create
  wrap do
    @my_model.save
    respond_with @my_model
  end
end

If you don't like the standard functionality, you can implement a single error handling method in your ApplicationController to handle errors from all wrapped action methods:

def on_action_error(error)
  case params[:format].to_sym
  when :json
    respond_with({errors: [error.message]}, location: nil, status: :internal_server_error)
  else
    raise error # should include prior backtrace
  end
end

Future

Originally was meant to provide a respond method that would skirt some of the unintuitive behavior of respond_with like #2798, and provide additional functionality, but that is commented for now. Maybe will get to it later. Feel free to fork/submit pull requests.

License

Copyright (c) 2012 Gary S. Weaver, released under the MIT license.