respond_supported_only

所属分类:WEB开发
开发工具:Ruby
文件大小:6KB
下载次数:0
上传日期:2015-02-04 02:16:02
上 传 者sh-1993
说明:  支持定义Rails控制器筛选器,该筛选器拒绝具有意外`Accept:`标头的请求。
(Support to defines Rails controller filter that rejects request with unexpected `Accept:` header.)

文件列表:
.rspec (53, 2015-02-04)
Gemfile (107, 2015-02-04)
LICENSE.txt (1061, 2015-02-04)
Rakefile (29, 2015-02-04)
lib (0, 2015-02-04)
lib\respond_supported_only.rb (668, 2015-02-04)
lib\respond_supported_only (0, 2015-02-04)
lib\respond_supported_only\version.rb (52, 2015-02-04)
respond_only_supported.gemspec (1127, 2015-02-04)
spec (0, 2015-02-04)
spec\rails_helper.rb (128, 2015-02-04)
spec\respond_only_supported_spec.rb (761, 2015-02-04)
spec\spec_helper.rb (541, 2015-02-04)
spec\support (0, 2015-02-04)
spec\support\rails_application.rb (318, 2015-02-04)

# RespondSupportedOnly :sparkles::sparkles::sparkles:**We are looking for twinkly name**:sparkles::sparkles::sparkles: Support to defines Rails' controller filter that rejects request with unexpected `Accept:` header. I unlike to write rails's `respond_to` and/or `respond_with` in all of actions. But without them, an application cause a ActionView::MissingTemplate if a request has unexpected `Accept:` header. Example: the request may cause error, `AV::MissingTemplate`. ``` $ curl -H 'Accept: image/png' -v -o /dev/null http://example.com/posts/42 ``` And 'causing errors' means that your error notification service will be filled with them. I try to protect my S:N ratio of notifications with less effort. ## Installation Add this line to your application's Gemfile: ```ruby gem 'respond_supported_only' ``` And then execute: $ bundle ## Usage Include `RespondSupportedOnly` in `ApplicationController` (or other controller super class) and declare `respond_only` with support formats argument and filter options. ```ruby # routes resources :posts do member do get :cover_image end end ``` ```ruby class PostsController < ApplicationController respond_only :html, :json, except: :cover_image respond_only :jpeg, :png, only: :cover_image def index ... end def show ... end end ``` ## Contributing 1. Fork it ( https://github.com/esminc/respond_supported_only/fork ) 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create a new Pull Request

近期下载者

相关文件


收藏者