Creating a gem with init.rb Rails 3

init, ruby, ruby-on-rails, rubygems

Solution

init.rb is not called anywhere for anyone, rename your file from TS3Query.rb to ts3query.rb and bundler will load it automatically for you.

Avoid using names with upper and lower case charaters, Linux and some Macs have case-sensitive file systems and while it works for someone might not work for everyone else.

Problem

I created a new gem: https://github.com/tntwebsolutions/ts3query In my init.rb file I `require` the main lib file, this should autoload the gem when the rails application is loaded. But when I start the server it seams that the `init.rb` file gets not loaded. In my application I have this in my `Gemfile`: ``` gem "ts3query", "~> 0.2.1" ``` And do this in my `application_controller.rb`: ``` @query = TS3Query.connect :password => password ``` But then I get this error: ``` uninitialized constant ApplicationController::TS3Query ``` If I do this: ``` require 'TS3Query' @query = TS3Query.connect :password => password ``` It does works. But I can't figure out, what I have to change at my gem to load the `require 'TS3Query'` when the rails application is loaded.

Original source