Git Product home page Git Product logo

white_list_model's Introduction

WhiteListModel

Instead of using white_list_helper in every view just use it as model before_filter! This way you don’t have to escape/whitelist user-input data in every place they appear, just filter it on save.

Usage

class News < ActiveRecord::Base
  white_list  # Filter all string or text fields with standard filter set
end

class News < ActiveRecord::Base
  white_list :only => :description  # Filter description field with standard filter set
end

class News < ActiveRecord::Base
  white_list :except => [:title, :description], :profile => :mini # Filter everything except :title and :description with :mini profile
  white_list :only => :description, :method => :update, :profile => :web # Filter :description with :web profile and everything else except :title with :mini profile
end

Avalible parameters

:only => []          # Filter only included fields
:except => []        # Filter all string or text fields except included
:attributes => []    # Add specified attributes to allowed list
:bad_tags => []      # Add specified tags to completely trim
:protocols => []     # Add specified protocols to allowed list
:tags => []          # Add specified tags to allowed list
:profile => :default # Load specified profile. If no profile given then :default will be used. Avalible profiles :empty, :mini, :base, :web and :default
:method => :update   # You can use more than one set of parameters. Default method is :replace - when you use it then all previous options will be erased. But with :update method you can collect as many combinations as you want(see example above)

Profile will be used as template, and other options will be merged, so if you want options to be fully customized, use empty profile.

Copyright © 2008 Bernard Potocki, released under the MIT license

white_list_model's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

mixr darkliquid

white_list_model's Issues

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.