Rails 3 Plugin v Gem using /app

I’m accustomed to making plugins for Rails 2, and recently updated those
for Rails 3 (minor differences in structure). Spent most of this week
figuring out how to make most of those gems.

One of them I am having trouble with – this one involves an /app
directory with some helpers and some views. It has worked great as a
Rails2 and even Rails3 plugin. As a gem, I can’t seem to get Rails to
see the files in /app.

I’ve been using jeweler. I don’t use git, so I have been manually
specifying files like this:

Jeweler::Tasks.new do |gem|
#…
gem.files.include(‘app//*.rb’)
gem.files.include('lib/
/*.rb’)
#…
end

That’s apparently not enough. The code in the gem works until the main
app hits something needed from the gem’s /app folder.

I’m missing something. Googling and trial & error are failing me.

What clue say ye? Thx.

– gw

Devise ( GitHub - heartcombo/devise: Flexible authentication solution for Rails with Warden. ) adds some views,
controllers and helpers so you can look at the code. Maybe you are
missing the fact that you need Rails::Engine ?
devise/lib/devise/rails.rb at main · heartcombo/devise · GitHub

I think that Yehuda K. has a post about it.

Robert Pankowecki

Robert Pankowecki wrote:

Devise ( GitHub - heartcombo/devise: Flexible authentication solution for Rails with Warden. ) adds some views,
controllers and helpers so you can look at the code. Maybe you are
missing the fact that you need Rails::Engine ?
devise/lib/devise/rails.rb at main · heartcombo/devise · GitHub

Thanks for the example. Interesting that it doesn’t use the same pattern
as all the blog posts I can find use (re: engines.rb file). Hmmm…

– gw

Keith S. wrote:

Greg, I have a working example that covers a bunch of gem features, it
might help you:
Keith Schacht – Medium

OK, so to make use of a /app folder, the gem must be an engine.

Keith, I’ve been using your example (thanks) and about a half dozen
articles, but still running into problems having the contents in the
/app folder get included using this:

Jeweler::Tasks.new do |gem|
#…
gem.files.include(‘app//*.rb’)
gem.files.include('lib/
/*.rb’)
#…
end

I’ve converted almost a dozen of my plugins to gems (so I seem to have
that pattern at least emulated well (if not yet fully understood)), and
now need two engines. I have one sort of working. The basics all work,
so I have the engine.rb part worked out, but it is still missing some
/app folder content after I create the gem.

I think I just spotted a pattern. In this line,
gem.files.include('app//*.rb’)
I am not familiar with /
/ but I’m now seeing that in the /app folder,
a layout like this:

So,
/app
/models
model1.rb
/views
/red_stuff
red1.rb.rb
/blue_stuff
blue1.rb.rb

in my installed gem I see /models but not /views – and I think that’s
because /views doesn’t have any .rb files in it.

So, I think the root of the problems I’m seeing is understanding the
files.include() part of jeweler to get what I need (Note: I am not using
git).

Looking at the ruby gems docs, I don’t see any examples of files.include
– so it’s still confusing as to which of these settings commands use
gem syntax and which uses jeweler syntax.

– gw

Greg, I have a working example that covers a bunch of gem features, it
might help you:
http://keithschacht.com/creating-a-rails-3-engine-plugin-gem/

So, I think the root of the problems I’m seeing is understanding the
files.include() part of jeweler to get what I need (Note: I am not using
git).

Oi! What a moron.

gem.files.include(‘app/**/*.rb’)

There are no .rb files in /views!

gem.files.include(‘app//*.rb’)
gem.files.include('app/
/*.erb’)

catches them.

Major thwak to the forehead.

– gw

Ah, I didn’t catch that in your post either. Glad to see you figured
it out!