0

I currently am working on a project where I have a main application that has several hosted engines. One of these engines is for the authentication and session handling that is currently stored in the main application in its own root folder.

I wish to create a gem from this folder and import it to the main application so that it can be used to make authentication calls for the user and session etc.

How can I go about creating a gem from this folder and making the classes and methods within available to the main application.

Any information or links you have on this would be greatly appreciated.

Jay
  • 3,012
  • 14
  • 48
  • 99
  • I am not clear on whether you want to create a gem from scratch or add an existing gem to your project. If you want to create a gem, this [railscast](http://railscasts.com/episodes/135-making-a-gem) might be helpful. If you are looking to add an existing gem to your project, then you can add it to your Gemfile and run `bundle install`. – diasks2 May 03 '12 at 12:41
  • Hi Diasks, I have a folder called "Authenticate" inside my main application which is mounted as an engine. I want to create a gem from the folder so that the models and controllers of Authenticate can then be called from my main application – Jay May 03 '12 at 13:15
  • I was following this tutorial http://guides.rubygems.org/make-your-own-gem/#first-gem, but whereas in this the top level is Class Hola mine is Module authenticate and I am not sure when i try to user the require GEMNAME statement it fails and when i try 'authenticate.hi' code in the irb I am getting the error message undefined method for Authenticate:Module – Jay May 03 '12 at 13:59
  • I don't have enough info about your project, but wouldn't it be easier to use an [authentication gem](https://github.com/plataformatec/devise) or [handle it without a gem](http://railscasts.com/episodes/250-authentication-from-scratch) instead of reinventing the wheel? – diasks2 May 03 '12 at 14:06
  • The authenticate folder has details of roles and permissions and is something that will be called by the individual mounted engines, this is why I require it to be a gem – Jay May 03 '12 at 14:08

1 Answers1

0

RailsCasts covers the basic structure of a mountable Rails Engine (the gemspec allows it to be Rails 4 compatible). http://railscasts.com/episodes/277-mountable-engines.

Might be a good place to start, and then come back with more questions.

westonplatter
  • 1,475
  • 2
  • 19
  • 30