Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sinatra_permitted_params

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sinatra_permitted_params

  • 0.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

SinatraPermittedParams

A simple parameter filtering for Sinatra

Installation

Add this line to your application's Gemfile:

gem 'sinatra_permitted_params'

And then execute:

$ bundle

Or install it yourself as:

$ gem install sinatra_permitted_params

Usage

This gems allows you to define your permitted params.

Add it as a helper in your sinatra App:

  require 'sinatra/base'
  require 'sinatra/permitted_params'

  class App < Sinatra::Base
    helpers Sinatra::PermittedParams
    #...

And define your permitted params:

  require 'sinatra/base'
  require 'sinatra/permitted_params'

  class App < Sinatra::Base
    helpers Sinatra::PermittedParams

    post '/comment' do
      permitted_params = permitted_params([:title, :body])
      comment = Comment.create(permitted_params)

      #...
    end
  end

  # GET /comment?title=comment&body=new%20params%20gems
  # GET /comment?title=comment&body=new%20params%20gems&user=new_user  raises <Sinatra::PermittedParams::UnpermittedParamsError: Unpermitted params found: invalid>

If a parameter different than the declared ones is received, then it raises a Sinatra::PermittedParams::UnpermittedParamsError.

Adding keys to the option 'ignore' allows you to define the params you want to filter without raising the error:

  post '/comment' do
    permitted_params = permitted_params([:title, :body], ignore: [:user])
    comment = Comment.create(permitted_params)

    #...
  end

In this case the param 'user' will be ignored, no error will be raised and the permitted_params will return a hash with title and body.

You can intercept the error with a Sinatra error do...end block

error Sinatra::PermittedParams::UnpermittedParamsError do
  #...
end

Contributing

  1. Fork it ( https://github.com/[my-github-username]/sinatra_permitted_params/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

FAQs

Package last updated on 01 Mar 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc