about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEffy Elden <git@effy.is>2017-01-21 20:22:49 +1100
committerEffy Elden <git@effy.is>2017-01-21 20:22:49 +1100
commit5fef55c11a7ea855e7b43ed274558a0893d0dc16 (patch)
tree3d5e2de6549b299a6c132d8d2f3e8898a1c232c0
parent1aae0cfc2c3a8c9f1748ae0f359ff00672e89bf1 (diff)
Set remote dev environments to use letter_opener_web, add default .env.vagrant variables
-rw-r--r--.env.vagrant1
-rw-r--r--Gemfile1
-rw-r--r--Gemfile.lock7
-rw-r--r--config/environments/development.rb10
-rw-r--r--config/routes.rb6
5 files changed, 23 insertions, 2 deletions
diff --git a/.env.vagrant b/.env.vagrant
new file mode 100644
index 000000000..0ab0552c9
--- /dev/null
+++ b/.env.vagrant
@@ -0,0 +1 @@
+VAGRANT=true
\ No newline at end of file
diff --git a/Gemfile b/Gemfile
index bab7cebb5..ebee7e35f 100644
--- a/Gemfile
+++ b/Gemfile
@@ -73,6 +73,7 @@ group :development do
   gem 'better_errors'
   gem 'binding_of_caller'
   gem 'letter_opener'
+  gem 'letter_opener_web'
   gem 'bullet'
   gem 'active_record_query_trace'
 end
diff --git a/Gemfile.lock b/Gemfile.lock
index 20ea37fcc..0e720d7fb 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -176,6 +176,10 @@ GEM
       addressable (~> 2.3)
     letter_opener (1.4.1)
       launchy (~> 2.2)
+    letter_opener_web (1.3.0)
+      actionmailer (>= 3.2)
+      letter_opener (~> 1.0)
+      railties (>= 3.2)
     link_header (0.0.8)
     lograge (0.4.1)
       actionpack (>= 4, < 5.1)
@@ -432,6 +436,7 @@ DEPENDENCIES
   jbuilder (~> 2.0)
   jquery-rails
   letter_opener
+  letter_opener_web
   link_header
   lograge
   nokogiri
@@ -474,4 +479,4 @@ RUBY VERSION
    ruby 2.3.1p112
 
 BUNDLED WITH
-   1.13.6
+   1.13.7
diff --git a/config/environments/development.rb b/config/environments/development.rb
index 829edcf04..476f3d74c 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -62,7 +62,15 @@ Rails.application.configure do
   # routes, locales, etc. This feature depends on the listen gem.
   # config.file_watcher = ActiveSupport::EventedFileUpdateChecker
 
-  config.action_mailer.delivery_method = :letter_opener
+  # If usng a Heroku, Vagrant or generic remote development environment,
+  # use letter_opener_web, accessible at  /letter_opener.
+  #
+  # Otherwise, use letter_opener, which launches a browser window to view sent mail.
+  if (ENV['HEROKU'] || ENV['VAGRANT'] || ENV['REMOTE_DEV'])
+    config.action_mailer.delivery_method = :letter_opener_web
+  else
+    config.action_mailer.delivery_method = :letter_opener
+  end
 
   config.after_initialize do
     Bullet.enable        = true
diff --git a/config/routes.rb b/config/routes.rb
index 4606c663a..0fcbc266d 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -3,6 +3,12 @@
 require 'sidekiq/web'
 
 Rails.application.routes.draw do
+
+  # Development-only routes
+  if Rails.env.development?
+    mount LetterOpenerWeb::Engine, at: "/letter_opener"
+  end
+
   mount ActionCable.server, at: 'cable'
 
   authenticate :user, lambda { |u| u.admin? } do