Rails 3 and Gem Plugins

21 views
Skip to first unread message

Sam Granieri

unread,
Jan 19, 2010, 10:30:18 PM1/19/10
to Ruby on Rails: Core
Will there be a way for rails 3 to load plugins from gems that have
been installed via the bundler?

Ryan Bigg

unread,
Jan 19, 2010, 10:37:45 PM1/19/10
to rubyonra...@googlegroups.com
Could you elaborate? An example on what gem you're trying to use would be helpful!

2010/1/20 Sam Granieri <s...@samgranieri.com>
Will there be a way for rails 3 to load plugins from gems that have
been installed via the bundler?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To post to this group, send email to rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-co...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.






--
Ryan Bigg

Yehuda Katz

unread,
Jan 19, 2010, 10:45:19 PM1/19/10
to rubyonra...@googlegroups.com
Yes.

I am working on a blog post now, but the basic idea is that ActionController, ActiveRecord, etc. are all "plugins" now. So anything that they can do, you can do too.

We just need to document how it works (if you're interested, check out the railtie.rb files in the various components).

Yehuda Katz
Developer | Engine Yard
(ph) 718.877.1325


On Tue, Jan 19, 2010 at 7:30 PM, Sam Granieri <s...@samgranieri.com> wrote:
Will there be a way for rails 3 to load plugins from gems that have
been installed via the bundler?

Martin Gamsjaeger

unread,
Jan 19, 2010, 10:47:59 PM1/19/10
to rubyonra...@googlegroups.com
You can also have a look at http://github.com/dkubb/rails3_datamapper
for an example of a gem/plugin (whatever the difference is) that works
with rails3

cheers
snusnu

Sam Granieri

unread,
Jan 20, 2010, 1:14:02 AM1/20/10
to Ruby on Rails: Core
Sure thing. I'm trying to get Jammit working as a gem on edge. Jammit
is an asset compressor and packager that I use on a side project. I
forked it at http://github.com/samgranieri/jammit/tree/rails3 and
proceeded to convert it to a rails 3 plugin. Jammit has a controller
for packaging the stylesheets/javascripts, a helper for displaying the
assets, and a route to display the assets.

If you install jammit as a plugin (via ./script/plugin install
git://github.com/samgranieri/jammit.git -r rails3) and type rake
routes, then the plugin loader will pick up the asset routes.

If you install jammit via the bundler, then type rake routes, then the
asset route wont show up. I tried installing it as a gem using a
locally checked out repo switched to the rails 3 branch.

Here's my gemfile lines for Jammit:

directory "/Users/sam/Documents/Development/ruby/gems/jammit"
gem 'jammit'

I hope this helps.

-- Sam


On Jan 19, 9:37 pm, Ryan Bigg <radarliste...@gmail.com> wrote:
> Could you elaborate? An example on what gem you're trying to use would be
> helpful!
>
> 2010/1/20 Sam Granieri <s...@samgranieri.com>
>
>
>
>
>
> > Will there be a way for rails 3 to load plugins from gems that have
> > been installed via the bundler?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Ruby on Rails: Core" group.
> > To post to this group, send email to rubyonra...@googlegroups.com.
> > To unsubscribe from this group, send email to

> > rubyonrails-co...@googlegroups.com<rubyonrails-core%2Bunsubscrib e...@googlegroups.com>

Mislav Marohnić

unread,
Jan 20, 2010, 4:39:01 AM1/20/10
to rubyonra...@googlegroups.com
On Wed, Jan 20, 2010 at 04:45, Yehuda Katz <wyc...@gmail.com> wrote:

I am working on a blog post now, but the basic idea is that ActionController, ActiveRecord, etc. are all "plugins" now. So anything that they can do, you can do too.

During the boot process, their respective "railtie.rb" scripts are required. Should we also write and later require "railtie.rb" from our plugins in application.rb, or will this be automatized ("railtie.rb" will have some magic behavior)?

Yehuda Katz

unread,
Jan 20, 2010, 4:48:03 AM1/20/10
to rubyonra...@googlegroups.com
This is one of the things we're working out.

The easiest thing to do is to put the Railtie subclass in lib/my_lib.rb itself. The bundler will require the file, similar to how config.gem worked in Rails 2.3.

Another option would be to move it into lib/my_lib/railtie.rb (or whatever) and require it from my_lib.rb. You can then do require "my_lib/railtie" if defined?(Rails), since the Rails constant will always be required before your gems (check out boot.rb if you want to see how).

You could also ask your users to require my_lib/rails or :require_as => ["my_lib", "my_lib/rails"] in bundler.

We're looking at some other, long-term options involving Rubygems metadata to further automate that process (perhaps you'd include some metadata in Rubygems registering your gem as a "plugin for rails >= 3.0 with lib/my_lib/railtie.rb" which would tell bundler to require that file, but only if Rails was around. 

Bottom line: there's a bunch of options right now, and the community should really converge on a few really good ones. I personally like putting the railtie in lib/my_lib.rb for gems that are only used as Rails plugins.

Yehuda Katz
Developer | Engine Yard
(ph) 718.877.1325


Mislav Marohnić

unread,
Jan 20, 2010, 9:52:23 AM1/20/10
to rubyonra...@googlegroups.com
On Wed, Jan 20, 2010 at 10:48, Yehuda Katz <wyc...@gmail.com> wrote:

Another option would be to move it into lib/my_lib/railtie.rb (or whatever) and require it from my_lib.rb. You can then do require "my_lib/railtie" if defined?(Rails), since the Rails constant will always be required before your gems (check out boot.rb if you want to see how).

So, the bottom line is that we (users, plugin authors) are responsible that the Railtie subclass somehow gets executed, either automatically in plugin code or explicitly with Bundler :require_as.

That's what I wanted to know. I guess this is all we need, since with Railtie we can hook into initializer and fine-tune what our plugin does at any specific stage of application loading.

I suggest you write a post on how Railtie subclasses look like, what they can do and what are the options of hooking into the initializer other than simply appending new initialization steps to the list.

Mikel Lindsaar

unread,
Jan 21, 2010, 5:48:30 AM1/21/10
to rubyonra...@googlegroups.com
On Thu, Jan 21, 2010 at 1:52 AM, Mislav Marohnić <mislav....@gmail.com> wrote: 
I suggest you write a post on how Railtie subclasses look like, what they can do and what are the options of hooking into the initializer other than simply appending new initialization steps to the list.

You can also look at the latest docs on railtie.rb that I just added at:


Which is commit #087b67805e3785 on lifo/docrails

It will be merged back into rails-master soon.

I am currently doing docs for all the railtie methods etc, so anything that is not clear, please let me know.

Mikel


--
http://lindsaar.net/


Mikel Lindsaar

unread,
Jan 21, 2010, 5:51:08 AM1/21/10
to rubyonra...@googlegroups.com
On Thu, Jan 21, 2010 at 9:48 PM, Mikel Lindsaar <raas...@gmail.com> wrote:
 
You can also look at the latest docs on railtie.rb that I just added at:

Having just re-read that again now, it needs much more work, for example it omits to mention that you need to require the railtie file and doesn't mention the other method that Yehuda went over.

But it is a start :)

I'll fix it up tomorrow.

Mikel

Sam Pohlenz

unread,
Jan 21, 2010, 12:07:30 AM1/21/10
to rubyonra...@googlegroups.com
On 20/01/2010, at 8:18 PM, Yehuda Katz wrote:
> The easiest thing to do is to put the Railtie subclass in lib/my_lib.rb itself. The bundler will require the file, similar to how config.gem worked in Rails 2.3.

Is this actually the case at the moment? As far as I can see, there's no Bundler.require_env call anywhere in the Rails initialization. Should there be one somewhere to ensure that bundled gems are required?

The only way I have been able to load my gem plugin is using an explicit require at the bottom of boot.rb.

-Sam Pohlenz

Owen Dall

unread,
Jan 20, 2010, 10:12:51 AM1/20/10
to rubyonra...@googlegroups.com
Yes, a post on this would be very useful.



--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To post to this group, send email to rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-co...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.




--
Thanks,

Owen

Owen Dall
Barquin International
410-991-0811
Reply all
Reply to author
Forward
0 new messages