0

I am starting two new projects and will be writing the authentication from scratch - what is the best way to share/copy this code on to the second app?

If there isn't a best way, what are the options? (Aside from using an auth library such as Devise)

A4J
  • 879
  • 10
  • 24

1 Answers1

1

You have a variety of options:

  1. Create a gem and require it in both apps
  2. Create an engine: http://edgeguides.rubyonrails.org/engines.html
  3. VC your app with git and write your auth piece, then branch off
  4. Copy and paste some code :)

Myself, I'd look carefully at 1 and 2, it would be the easiest way to push updates to both apps and maintain a single authentication codebase. And, as a bonus, you'll be forced to abstract your authentication layer.

agmin
  • 8,948
  • 2
  • 21
  • 27
  • Thanks, I really like the idea of creating (my first!) gem (or engine). Would there be a way to make it private tho - so only I can use/see them? ...I'm not sure I have the confidence for it to be public tbh. – A4J Oct 11 '13 at 00:36
  • Definitely. You can include gems from private github repos, local paths etc. http://stackoverflow.com/questions/4487948/how-can-i-specify-a-local-gem-in-my-gemfile – agmin Oct 11 '13 at 00:37
  • Awesome, thanks! Now just to decide between an engine or gem - any thoughts? (I'm leaning towards a gem, as I don't think I'll need the flexibility of an engine.) – A4J Oct 11 '13 at 00:42
  • 1
    If you go for the basic option (number 4) you can create a base for your apps and then when you need to reuse it and make a new app you give it a new name with [Rename Gem](https://github.com/get/Rename). The gem will change the name of the app everywhere where it needs to be changed. – JPG Oct 11 '13 at 00:49
  • Start with a gem - it can turn into an engine if needed – agmin Oct 11 '13 at 16:18