Blankman Blankman - 1 year ago 57
Ruby Question

Created a file S3Service but can't seem to load it

I created a simple file S3Service.rb


The file has:

require 'aws-sdk'

class S3Service
attr_accessor :region

def initialize
@region = 'us-east-1c'

def foo
puts "region is #{region}"

When I go into rails console I can't seem to be able to use this class.

>rails c
>require 'S3Service'
LoadError: cannot load such file -- S3Service

Are numbers not allowed in names?

I can create instances of other classes that I have in my lib folder so it is loading all my lib files correctly.

Answer Source

require takes the name of the file (optionally and conventionally without the .rb extension), not the name of the class. So you should change the require to:

require 's3_service'