1

I have the puma gem in my Rails 4.1.8 Gemfile because I want to use it as the default webserver in all environments. That works fine.

# Gemfile
gem "puma"

In development I am using mailcatcher which means that I'd like to include it as a dependency in my Gemfile.

# Gemfile
group :development do
  gem "mailcatcher"
end

This causes the default webserver to be set to thin. This appears to be an unintended consequence of mailcatcher, but it brings up a specific question. Can I create a group that bundler obeys to install Gems, but that Rails ignores? I tried something like this but Rails is still loading the contained gems.

# Gemfile
group :mailcatcher do
  gem "mailcatcher"
end
rb-
  • 2,315
  • 29
  • 41
  • 3
    [“Please don't put mailcatcher into your Gemfile. It will conflict with your applications gems at some point.”](http://mailcatcher.me/) I guess this is the type of thing they mean. – matt Jan 04 '15 at 18:54
  • Yup your application doesn't depend on it, even in development, so why shoehorn it into your application's Gemfile? `gem install mailcatcher`, done. Odds are there are other tools you use during development that are more involved to install, but since they aren't Ruby gems they obviously don't go in the Gemfile, this is the same thing. – Nick Veys Jan 04 '15 at 18:57
  • Fair enough. I just don't like the fact that I have to remember to manually install Gems when I spin up a new development environment. – rb- Jan 04 '15 at 19:03
  • It just seems like there should be a way to use the Gemfile to install Gems but have Rails ignore them. Maybe not. – rb- Jan 04 '15 at 19:04

3 Answers3

0

You can alias rails s command... For example export alias rs="rails server puma" and now rs will start puma. This way you are free to use any webserver you want ) If you want to make it really default you can add something like this

require 'rack/handler'
Rack::Handler::WEBrick = Rack::Handler.get(:puma)

to the rails script.

NilColor
  • 3,462
  • 3
  • 30
  • 44
  • That might work, but my question is really about having a Gem in my Gemfile that Rails doesn't load. I'm probably on the wrong track with that though. I removed `mailcatcher` from my Gemfile as the docs advised. – rb- Jan 04 '15 at 19:16
  • That will be strange - to have gem to not have it )) So... I'm not sure you can do this. You can add gem without require it... Maybe it helps. – NilColor Jan 04 '15 at 20:23
0

I don't know if this will work or not, but what about:

gem "mailcatcher", :require => false

Ref: Bundler: What does :require => false in a Gemfile mean?

Community
  • 1
  • 1
DGM
  • 26,629
  • 7
  • 58
  • 79
  • From the description it sound like exactly what I'm looking for, but it doesn't render the result I want. Rails still seems to require the gems with `:require` set to `false`. – rb- Jan 04 '15 at 19:24
  • sounds like mailcatcher just doesn't play nice. Have you considered https://github.com/ryanb/letter_opener ? – DGM Jan 04 '15 at 19:27
  • I'm just going to add a rake task that installs the other Gems required by `Mailcatcher`. If I find a better solution I'll update my question. – rb- Jan 04 '15 at 19:35
  • dumb question, but did you run bundle install after setting require false? – DGM Jan 05 '15 at 21:07
0

Mailcatcher specifically states to not put it in your Gemfile.

Please don't put mailcatcher into your Gemfile. It will conflict with your applications gems at some point.

Instead, pop a note in your README stating you use mailcatcher. Simply run gem install mailcatcher then mailcatcher to get started.

Community
  • 1
  • 1
anthonator
  • 4,915
  • 7
  • 36
  • 50