padrino/padrino-framework — Issue #762: Put 'padrino' gem at top of Gemfile instead of bottom?
Author: futurechimp
Created: 2012-01-21 08:49:10+00:00
State: open

Hi guys,

I'm trying to fix an integration problem between Padrino and CarrierWave. There isn't really a bug in either piece of software, but if you just try and use CarrierWave without setting some things up, it'll blow up in Padrino.

I've been talking to the CarrierWave devs about it over in https://github.com/jnicklas/carrierwave/issues/575

Basically, the CarrierWave boot sequence attempts to set a root path for file uploads when used with Sinatra or Rails.

The Sinatra integration is really simple, it looks like this:

```ruby
elsif defined?(Sinatra)

CarrierWave.root = if Sinatra::Application.respond_to?(:public_folder)
# Sinatra >= 1.3
Sinatra::Application.public_folder
else
# Sinatra < 1.3
Sinatra::Application.public
end

end
```

It doesn't work as Sinatra::Application.public_folder is nil at this point. This sets the CarrierWave upload root to nil, and causes all CarrierWave file uploads to explode.

The setting fails in Padrino, if I do something like this during CarrierWave loading (this is in the cw gem itself):

```ruby
elsif defined?(Padrino)
CarrierWave.root = File.join(Padrino.root, "public")
end
```

This dies because Padrino.root is nil until the padrino gems are loaded.

One thing I've noticed is that if I simply move the Padrino gem to the *top* of the Gemfile, so that it loads before everything else, then the above integration code works fine - that way, Padrino.root is available.

Is there a reason to have gem 'padrino' at the end of the Gemfile rather than at the beginning? It might ease this kind of integration if it was at the top, but I am not sure whether this is a conscious design choice on your part. Could it be moved to the bottom?