Giter VIP home page Giter VIP logo

hashids_rails's Introduction

hashids_rails gem

<img src=“https://badges.gitter.im/Join%20Chat.svg” alt=“Join the chat at https://gitter.im/brianpetro/hashids_rails”>

Uses hashids.rb(github.com/peterhellberg/hashids.rb) to store ActiveRecord IDs in URL non-obviously. Heavily based on obfuscate_id(github.com/namick/obfuscate_id).

Installation

Add the gem to your Gemfile.

gem 'hashids_rails'

Run bundler.

bundle install

Usage

In your model, add a single line.

class Post < ActiveRecord::Base
  hash_id
end

Customization

If you want your hash ids to be different than some other website using the same plugin, you can throw a random string (salt) at hash_id to make it hash out unique ids for your app.

class Post < ActiveRecord::Base
  hash_id salt: 'bring_your_own_salt'
end

Limitations

  • This is not security. hashids_rails was created to lightly mask record id numbers for the casual user. If you need to really secure your database ids (hint, you probably don’t), you need to use real encryption like AES.

  • To properly generate obfuscated urls(using hash_ids), make sure you trigger the model’s to_param method by passing in the whole object rather than just the id; do this: post_path(@post) not this: post_path(@post.id).

Contributing

TODO

  • write tests

hashids_rails's People

Contributors

brianpetro avatar gitter-badger avatar

Watchers

 avatar  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.