robintw
robintw

Reputation: 28601

Gem available in irb but not rails console

I am trying to use the RedCloth gem in my rails project. When I used irb I can load the gem:

require 'rubygems'
require 'RedCloth'

and it works fine, but when I try the same thing in the rails console I get an error message stating that the gem cannot be found.

Does anyone have any idea what might cause this?

Upvotes: 19

Views: 12779

Answers (3)

Mehtab Riaz
Mehtab Riaz

Reputation: 39

Above answer worked for me, but you need to add the load path to $: every time you open rails console. Simple solution is:

  • create ~/.irbrc if not exists.

  • add these lines:

     $: << '/home/mehtab/.rvm/gems/ruby-3.2.0/gems/awesome_print-1.9.2/lib/'
     require "awesome_print"
     AwesomePrint.irb!
    

Now everytime you run rails c ~/.irbrc will be loaded.

Upvotes: 0

Hitesh Sharma
Hitesh Sharma

Reputation: 533

You can append gem path to ruby load path. Do this:

gem which faker
=> /usr/local/ruby/......../faker-0.1.1/lib/faker.rb

Start Rails console and do the following:

$: << '/usr/local/ruby/......../faker-0.1.1/lib/'

and now load faker gem

require 'faker'
=> true

Upvotes: 26

Dylan Markow
Dylan Markow

Reputation: 124469

Does your rails project's Gemfile include gem 'RedCloth' in it? Rails will only load the gems specified in that file.

Upvotes: 20

Related Questions