GithubHelp home page GithubHelp logo

sinatra-hashfix's Introduction

Sinatra::Hashfix - Use HashWithIndifferentAccess for Sinatra params

Get your hash fix!

Sinatra only partially implements a Rails style params[] hash, which can lead to confusing behavior, since methods like has_key?() and delete() don’t work as you’d expect:

groups.google.com/group/sinatrarb/browse_thread/thread/af4b40e610d4daf/bc953ca6d118a882

This gem replaces the default Sinatra params hash with HashWithIndifferentAccess (from ActiveSupport). Purists may balk, but this is all about avoiding bugs.

Installation

You know this tune:

gem install sinatra-hashfix

If you are using a classic (one-file) Sinatra app, just add:

require 'sinatra/hashfix'

If you are using a modular Sinatra::Base app, you must also add:

register Sinatra::Hashfix

To the top of your application class.

Example

Request:

/my/route?foo=1

Without:

params[:foo]            # 1
params.has_key?(:foo)   # false
params.has_key?('foo')  # true

With:

params[:foo]            # 1
params.has_key?(:foo)   # true
params.has_key?('foo')  # true

It’s the little things in life that make me happy.

Author

Copyright © 2010 Nate Wiger. All Rights Reserved. Released under the Artistic License.

sinatra-hashfix's People

Stargazers

Luke F avatar Kevon Cheung avatar Nate Wiger avatar Jeff Cornejo avatar

Watchers

Nate Wiger avatar James Cloos avatar

sinatra-hashfix's Issues

Why do you choose system ruby version?

My Debian PC can't build sinatra-hashfix. Because it stops with following error.
Why do you choose /usr/include/ruby-2.1.0/ruby/ruby.h? I think it's a header file on system ruby version....

$ uname -a
Linux masterq 3.16-3-amd64 #1 SMP Debian 3.16.5-1 (2014-10-10) x86_64 GNU/Linux
$ ruby --version
ruby 2.1.3p242 (2014-09-19) [x86_64-linux-gnu]
$ which ruby
/home/kiwamu/.rbenv/shims/ruby
$ bundle install --path vendor/bundle --without development test
--snip--
Fetching https://github.com/bmabey/database_cleaner.git
Fetching https://github.com/axsh/trema.git
Fetching https://github.com/axsh/rant.git
Fetching https://github.com/axsh/racket.git
Fetching gem metadata from http://rubygems.org/.........
Resolving dependencies...
Installing rake 10.1.1
--snip--
Installing sinatra 1.4.4
Installing sinatra-browse 0.3
Installing sinatra-contrib 1.4.2
Installing sinatra-hashfix 0.1.0

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /usr/bin/ruby2.1 -rubygems /home/kiwamu/src/openvnet/vnet/vendor/bundle/ruby/2.1.0/gems/rake-10.1.1/bin/rake RUBYARCHDIR=/home/kiwamu/src/openvnet/vnet/vendor/bundle/ruby/2.1.0/bundler/gems/extensions/x86_64-linux/2.1.0/trema-4f82057b5988 RUBYLIBDIR=/home/kiwamu/src/openvnet/vnet/vendor/bundle/ruby/2.1.0/bundler/gems/extensions/x86_64-linux/2.1.0/trema-4f82057b5988
cannot load such file -- yard
gcc -H -g -fPIC -std=gnu99 -D_GNU_SOURCE -fno-strict-aliasing -Werror -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion -Wfloat-equal -Wpointer-arith -Wno-error=sign-conversion -fPIC -I/home/kiwamu/src/openvnet/vnet/vendor/bundle/ruby/2.1.0/bundler/gems/trema-4f82057b5988/src/lib -I/home/kiwamu/src/openvnet/vnet/vendor/bundle/ruby/2.1.0/bundler/gems/trema-4f82057b5988/ruby/trema -I/home/kiwamu/src/openvnet/vnet/vendor/bundle/ruby/2.1.0/bundler/gems/trema-4f82057b5988/ruby/trema/messages -I/usr/include/ruby-2.1.0/x86_64-linux-gnu -I/usr/include/ruby-2.1.0/ruby/backward -I/usr/include/ruby-2.1.0 -c /home/kiwamu/src/openvnet/vnet/vendor/bundle/ruby/2.1.0/bundler/gems/trema-4f82057b5988/ruby/trema/action-common.c -o /home/kiwamu/src/openvnet/vnet/vendor/bundle/ruby/2.1.0/bundler/gems/trema-4f82057b5988/ruby/action-common.o
In file included from /usr/include/ruby-2.1.0/ruby.h:33:0,
                 from /home/kiwamu/src/openvnet/vnet/vendor/bundle/ruby/2.1.0/bundler/gems/trema-4f82057b5988/ruby/trema/action-common.c:21:
/usr/include/ruby-2.1.0/ruby/ruby.h:24:25: fatal error: ruby/config.h: No such file or directory
 #include "ruby/config.h"
                         ^
compilation terminated.

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.