Sha256: a46c2c9985b5827fc3cf08d85f643e083ecd602b6397d159a291d7c288489c25

Contents?: true

Size: 1.58 KB

Versions: 24

Compression:

Stored size: 1.58 KB

Contents

### Mailcatcher on load error

I got in love in `Mailcather` project, but there is one dizzy feature in it- if 
in your controller must be sent some mail and `Mailcatcher` daemon is not running
you will have an error (and it is oblivious). The is a sample code

```
  def create
    @review = Review.new(review_params)
    if @review.save
      flash.now[:notice] = "All ok!"
      Mailer.review_for_admin(@review).deliver  # <- Here it is
      respond_to do |format|
        format.js { render partial: "reviews/create" }
      end
    else
      flash.now[:alert] = @review.errors.full_messages.join(", ")
      respond_to do |format|
        format.js { render partial: "pages/flash" }
      end
    end
  end
```

Actually, you test mail services not very often, and, it will be good enough, if 
there will not be unneeded error and mail will be sent in 
`action_mailer.delivery_method = :test` or `action_mailer.delivery_method = :file`
mode. I preferred the second method. And there is the code, which it implements 
in `delelodment.rb`

``` 
Rails.application.configure do
  ...
  if system ('lsof -i :1025 | grep mailcatch > /dev/null')
    config.action_mailer.delivery_method = :smtp
    config.action_mailer.smtp_settings = { address: "localhost", port: 1025 }
  else
    config.action_mailer.delivery_method = :file
  end
end
```

This code will run only once, when `rails server` starts, so, it will not slow 
down your system. I hope it was useful!

[Kvoka](https://github.com/kvokka/)

PS: You may need to install `lsof` utility, if you have no it.
`sudo apt-get install lsof` will help in this case.

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
onotole-1.2.11 goodies/mailcatcher_loading_patch.md
onotole-1.2.10 goodies/mailcatcher_loading_patch.md
onotole-1.2.9 goodies/mailcatcher_loading_patch.md
onotole-1.2.8 goodies/mailcatcher_loading_patch.md
onotole-1.2.7 goodies/mailcatcher_loading_patch.md
onotole-1.2.6 goodies/mailcatcher_loading_patch.md
onotole-1.2.5 goodies/mailcatcher_loading_patch.md
onotole-1.2.4 goodies/mailcatcher_loading_patch.md
onotole-1.2.3 goodies/mailcatcher_loading_patch.md
onotole-1.2.2 goodies/mailcatcher_loading_patch.md
onotole-1.2.1 goodies/mailcatcher_loading_patch.md
onotole-1.1.21 goodies/mailcatcher_loading_patch.md
onotole-1.1.20 goodies/mailcatcher_loading_patch.md
onotole-1.1.19 goodies/mailcatcher_loading_patch.md
onotole-1.1.18 goodies/mailcatcher_loading_patch.md
onotole-1.1.17 goodies/mailcatcher_loading_patch.md
onotole-1.1.16 goodies/mailcatcher_loading_patch.md
onotole-1.1.15 goodies/mailcatcher_loading_patch.md
onotole-1.1.14 goodies/mailcatcher_loading_patch.md
onotole-1.1.13 goodies/mailcatcher_loading_patch.md