Skip to content

A simple Rails plugin to mix up resource ids a bit.

License

Notifications You must be signed in to change notification settings

dtaniwaki/obfuscatable

 
 

Repository files navigation

obfuscatable

Gem Version Dependency Status Build Status Code Climate

Make your ActiveRecord ids non-obvious

This gem is just a fork from obfuscate_id but I made the obfuscation optional because it affects to some conditions and causes errors.

Installation

Add the gem to your Gemfile.

gem "obfuscatable"

Run bundler.

bundle install

Usage

In your model, add a single line.

class Post < ActiveRecord::Base
  obfuscatable
end

Then use it with to_param or direct object passing in the view.

link_to 'Post', post_path(@post.to_param)
link_to 'Post', post_path(@post)

And in your controller.

class PostController < ApplicationController
  def show
    Post.find(params[:id], obfuscated: true)
  end
end

Customization

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

class Post < ActiveRecord::Base
  obfuscatable :spin => 89238723
end

About

A simple Rails plugin to mix up resource ids a bit.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 85.4%
  • HTML 10.5%
  • JavaScript 2.2%
  • CSS 1.9%