Please use Rails 3's new Responder syntax (I do), or Decent Exposure which has many of same funcitonality of exposure and a much larger community.
Exposure is a Rails is a controller abstraction layer like resource_this
, make_resourceful
and resource_controller
with the same goal: exposing resources at the controller level with fewer headaches.
class PostsController < ApplicationController
expose :posts
end
Exposure has a number of customization points:
Exposure uses ActiveSupport
's callback system and has the following callbacks:
before_find
after_find
after_find_on_failure
after_find_on_success
before_assign
after_assign
before_save
after_save
after_save_on_failure
after_save_on_success
before_create
after_create_on_failure
after_create_on_success
before_update
after_update_on_failure
after_update_on_success
before_destroy
after_destroy_on_success
before_response
before_response_on_success
before_response_on_failure
You can access these directly
class PostsController
before_find :do_somethng_special, :if => {|c| c.action_name == 'show' }
private
def do_somethng_special
...
end
end
or through a specialty syntax
class PostsController
before :find, :do_somethng_special, :only => [:create]
private
def do_somethng_special
...
end
end
$ sudo gem install exposure
# environment.rb
gem.exposure
(The MIT License)
Copyright (c) 2009 Trek Glowacki
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.