Do not put hyphens in engine names

I’m currently working on my first rails 3.1 engine and have just wasted a day or so because I put a hyphen in the engine name. The reason I did this was to be consistent with some other plug-ins I am using (e.g. noodall-core). The new plugin should provide polls for noodall sites. So noodall-poll would be consistent with other noodall plugins.

rails plugin new NoodallPoll --mountable

Created noodall_poll.

So instead I used:

rails plugin new noodall-poll --mountable

The result was lots of paths using noodall-poll, such as /app/helpers/noodall-poll/application_helper.rb. When I tried to run test, I got application_helper.rb not found errors. The system was looking for /app/helpers/noodall_poll/application_helper.rb.

Lesson learn: don’t play around with engine names. Use camelcase or underscored engine names.

An update:
This issue has raised its head again and following a google search and I came up with what I think should be the definitive answer:

If your gem lives in a parent name space, the name spaces should be separated with hyphens in the gem name. So Net::HTTP has a parent namespace of Net and a main namespace of HTTP, and so the gem name is net-http.

If your project name comprises multiple words, the words should be separated by underscores in the gem name. So a project with a namespace FooBar have the gem name foo_bar.

And to combine the two Net::FooBar should have the project name ‘net-foo_bar‘.

As for the folder structure in my original example: Noodall should have been the parent namespace, so the gem name would be noodall-poll, and the path to the helper should have been: /app/helpers/noodall/poll/application_helper.rb

This entry was posted in Ruby. Bookmark the permalink.