GithubHelp home page GithubHelp logo

isabella232 / what Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thoughtbot/what

0.0 0.0 0.0 108 KB

Adds boolean instance methods for MIME type checking to Rails

License: MIT License

Ruby 100.00%

what's Introduction

DEPRECATED

This plugin is now deprecated. If you would like to dispatch on the MIME type from within a Rails controller you should use the #respond_to method or the mobile_fu plugin.

What

What provides boolean query methods on Mime::Type instances for the native Rails mime-types. You now have these methods available from your controllers:

  • request.format.atom?

  • request.format.css?

  • request.format.csv?

  • request.format.html?

  • request.format.ics?

  • request.format.js?

  • request.format.json?

  • request.format.multipart_form?

  • request.format.rss?

  • request.format.text?

  • request.format.url_encoded_form?

  • request.format.xml?

  • request.format.yaml?

… and any custom mime types that you add in any environment specific config files.

Examples

# config/initializers/mime_types.rb

Mime::Type.register 'text/iphone', :iphone

# app/controllers/what_controller.rb

class WhatController < ApplicationController

  before_filter :csv?, :iphone?

  def index
    render :text => 'index'
  end

  protected

  def csv?
    if request.format.csv?
      redirect_to login_url
    end
  end

  def iphone?
    if request.format.iphone?
      redirect_to login_url
    end
  end

end

What is especially powerful in combination with When.

# app/controllers/what_controller.rb

class WhatController < ApplicationController

  before_filter :login, :if => :csv?
  before_filter :login, :if => lambda { |controller| controller.request.format.iphone? }

  def index
    render :text => 'index'
  end

  protected

  def csv?
    request.format.csv?
  end

  def login
    redirect_to login_url
  end

end

Copyright © 2008 Dan Croak, Jared Carroll, and thoughtbot, inc. released under the MIT license

what's People

Contributors

mike-burns avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.