Cannot install hashids gem on (ruby/sinatra)

147 Views Asked by At

I installed hashids gem as instructed here: https://github.com/peterhellberg/hashids.rb

However, when I try to use the Hashids class it shows me an error as if it doesn't know this class:

NameError at / uninitialized constant Hashids

This is the code where it fails:

tocode = Hashids.new("test")

I am not even sure how to debug this as I am new to ruby. I know that the class is defined in the Hashids library. I don't think I am supposed to use 'required' as I installed this as a gem. When I run 'gem list' I see that gem there:

hashids (1.0.3)

1

There are 1 best solutions below

1
On

After you installed the Hashids gem, it will not add to your $LOAD_PATH by default, when your say Hashids.new("test") ruby will try to find Hashids in your $LOAD_PATH, it will raise NameError at / uninitialized constant Hashids once it can't be found. To append Hashids to your $LOAD_PATH, your need

require "hashids"

before you use it.