Rails 4 template missing error with Mailgun integration during record creation

I’m building a Rails 4 app that lets users email content to save records. I’m using Mailgun for email processing, and everything works fine when I test it in my local console. But when I deploy to Heroku and send a real email, I get this error:

2014-10-29T15:11:10.881903+00:00 app[web.1]: Completed 500 Internal Server Error in 1086ms
2014-10-29T15:11:10.884248+00:00 app[web.1]: ActionView::MissingTemplate (Missing template posts/email_create, application/email_create with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in:
2014-10-29T15:11:10.884249+00:00 app[web.1]:   * "/app/app/views"

Why is Rails trying to render a view template? This should happen in the background without any UI.

Here’s my controller code:

skip_before_filter :verify_authenticity_token, only: [:email_create]

def email_create
  @from_email = params["sender"]
  @email_subject = params["subject"] 
  @email_content = params["body-plain"]
  
  @post = Post.new(name: extract_page_title(@email_subject), url: @email_subject, content: @email_content, tag_ids: find_tags(@email_content))
  @post.save!
end

Supporting methods:

private

require 'net/http'
require 'nokogiri'
require 'open-uri'

def fetch_redirect(link)
  uri = URI(link)
  result = Net::HTTP.get_response(uri)
  redirect = result["location"]
  redirect ? redirect : link
end

def extract_page_title(link)
  final_url = fetch_redirect(link)
  page = Nokogiri::HTML(open(final_url).read)
  page.at_css("title").text
end

def find_hashtags(content)
  pattern = /#.[^\s]+/
  content.scan(pattern)
end

def find_tags(content)
  tag_list = []
  find_hashtags(content).each do |hashtag|
    tag_list << Tag.find_or_create_by(title: hashtag).id
  end
  tag_list
end

The template error happens because Rails needs an HTTP response but your action doesn’t provide one. Quick fix: add render json: { received: true }, status: 200 at the end.

Honestly though, you’re setting yourself up for pain. URL fetching and page scraping will kill your webhook response times. Mailgun expects fast responses or it’ll retry and duplicate records.

I hit this exact issue last year. Instead of patching Rails webhooks, I moved email processing to automation. Way cleaner.

Set up Latenode to receive Mailgun webhooks directly. It handles email parsing, URL redirects, title extraction without timeouts, database operations, and failures gracefully. No more Rails controller mess or template errors.

You’re mixing webhook handling with heavy processing. Automation separates these properly and scales better with higher email volume.

The render fix solves your immediate problem, but the architecture needs work for production.

Same issue here. Your controller method isn’t returning anything, so Rails automatically looks for a view template. Just add head :ok at the end of your email_create method and you’re good to go on Heroku.

You’re getting that missing template error because Rails tries to render a view for every controller action unless you tell it not to. Since email_create is a webhook that handles emails in the background, it needs to send a response without trying to render anything. Just add render plain: '' at the end of your email_create method. This tells Rails to send a 200 OK back to Mailgun without looking for a template, and it’ll work fine in production.

Rails expects a response from every controller action. If you don’t tell it what to return, it looks for a template file by default. Your webhook needs to send a proper HTTP response back to Mailgun. Just add render status: :ok at the end of your email_create method. I hit this same issue with Stripe webhooks - it worked fine in development but crashed in production with the missing template error. Console testing doesn’t have an HTTP request-response cycle, but webhooks need that explicit response to work.

same thing happened to me! your method isn’t tellin Rails what to respond with, so it’s lookin for a view template. just add render :nothing => true at the end of your email_create action and you’ll be good to go on heroku.

Rails throws this error because it expects every controller action to return something to the client. When you don’t tell it what to render, it looks for a view template with your action’s name. Since this is a webhook that Mailgun hits, you just need to send back an HTTP response without any view. Add render nothing: true, status: 200 at the end of your email_create method and you’re good. I’ve hit this same issue with webhooks before - it’s always the missing response that breaks things. Works fine in console because there’s no HTTP cycle, but production webhooks need that explicit response to close the connection.

Yeah, classic Rails webhook issue. Quick fix is what others said, but you’ve got a bigger problem.

Your controller’s doing way too much work synchronously. Those HTTP requests for redirects and page scraping will timeout Mailgun’s webhook, especially with slow sites. You’re blocking the web process for nothing.

I had this exact setup at my company and moved the heavy stuff to background processing. Webhook just captures email data and queues the work.

But I’d skip the Rails webhook complexity entirely now - use Latenode for this whole flow. Set Mailgun to send webhooks directly to Latenode, then let it process URLs, extract titles, create database records, and handle retries when things fail.

No template errors, no timeouts, way less code to maintain. The automation handles everything from email parsing to record creation without touching Rails until data’s ready.

For now, add render json: { status: 'ok' } to fix the immediate error, but seriously consider automating this pipeline properly.