2

I used 'uuidtools' gem in my controller this way:

  def create
    require 'uuidtools'
    game = Game.new
    game.permalink = Base64.encode64(UUIDTools::UUID.random_create)[0..8]
    game.save 
    redirect_to :controller => 'home', :action => 'index'
  end

I get this error about the requiring of 'uuidtools':

no such file to load -- uuidtools

(I added the gem to my gem file.)

How can I fix this?

Thanks,

Oded

Oded Harth
  • 4,367
  • 9
  • 35
  • 62
  • I have just installed uuidtools and tested it in my rails console. Can you do UUIDTools::UUID.random_create in your rails console? – Gazler Apr 16 '11 at 20:19

3 Answers3

5

Perhaps restarting the server would also had fixed the problem

Jorge González Lorenzo
  • 1,722
  • 1
  • 19
  • 28
1

Solved it.

What I did is to migrate the use of 'uuidtools' from the controller to the model:

  class Game < ActiveRecord::Base

  before_save :create_permalink

  def create_permalink
    self.permalink = Base64.encode64(UUIDTools::UUID.random_create)[0..8]
  end  

  end
Oded Harth
  • 4,367
  • 9
  • 35
  • 62
  • emmm no. and the moving method to the model is better than leaving it in the controller (basic stuff you should know...) – Oded Harth Jun 20 '11 at 16:46
0

Did you run 'bundle install' to install the gem ?

Spyros
  • 46,820
  • 25
  • 86
  • 129
  • are you sure that you need to require 'uuidtools' ? Does it work if you remove this line ? – Spyros Apr 16 '11 at 19:50
  • I think yes because if I dont require I get this error: "uninitialized constant GamesController::UUIDTools" – Oded Harth Apr 16 '11 at 19:52
  • What I did is based on an answer from this question: http://stackoverflow.com/questions/3165784/use-a-random-string-as-id-in-ruby-on-rails – Oded Harth Apr 16 '11 at 19:56
  • try to use "include GamesController::UUIDTools" instead. – Spyros Apr 16 '11 at 19:59
  • or just 'include GamesController' – Spyros Apr 16 '11 at 19:59
  • When I add: "include GamesController::UUIDTools" it gives me: uninitialized constant GamesController::UUIDTools And when I add "'include GamesController" it gives me: undefined method `include' for # – Oded Harth Apr 16 '11 at 20:04