2

I have an Exception notifier set up in my rails application. So today I got the second notification, that the index template is missing:

An ActionView::MissingTemplate occurred in products#index:

Missing template products/index, application/index with {:locale=>[:en, :de], :formats=>["text/html;text/plain"], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :slim, :arb, :jbuilder]}. Searched in:
* "/home/releases/20160518143810/app/views"


-------------------------------
Request:
-------------------------------

* URL : http://example.com/shop
* HTTP Method: GET
* IP address : xx.xx.xx.xx
* Parameters : {"controller"=>"products", "action"=>"index"}
* Timestamp : 2016-06-07 08:19:13 +0200
* Server : vintage-shop.ch
* Rails root : /home/releases/20160518143810
* Process: 15714

I know for a fact, that the product's index template is there on the server and checked in in VCS and the application has been running for month now. So I really wonder, why this can happen:

$ ls /home/releases/20160518143810/app/views/products/index.html.slim 

# -> /home/releases/20160518143810/app/views/products/index.html.slim

How is this exception possible?

Update: I looked up the IP Address and it is not from the region where I would expect my customers to be from. So I am wondering if this is some sort of attack, but then the question still remains how an exception can be triggered, even though the template is present.

Besi
  • 22,579
  • 24
  • 131
  • 223

1 Answers1

1

It might be an attack attempt or (more probably I guess) some random noise. The problem seems to be in the format that Rails parsed out from the request headers. Normally, you should see something like: :formats=>[:html, :text, :js, :css, :ics] in the exception message.

The format is generally determined in rails using the request URI (usually everything after a dot '.' is considered a format specification) or using the Accept header. In your case it is the header I guess (you should be able to see the header in the exception notification). The Accept header should contain comma-separated content types, not semicolon-separated, so I guess this is the actual source of the exception.

Take a look at this very insightful blog post if you want more details about Rails format resolution.

Matouš Borák
  • 15,606
  • 1
  • 42
  • 53
  • Yes exactly this is what I was thinking. This can be tell with more confidence if I could see, actual rails log when server request came. Because that log is very detail to answer the view rendering issues. – Arup Rakshit Jun 07 '16 at 08:41
  • Thanks for your details. The `Accept` headers are in fact semicolon seperated. Is there a way for rails to fallback to html and not throw an exception? – Besi Jun 07 '16 at 08:50
  • I don't know about the fallback to html but you should at least be able to show a 404 not_found page or something similar using [`rescue_from`](http://stackoverflow.com/a/14566690/1544012). It's a client error anyway so I think showing an error page is correct in such case. However be warned that with this approach you will never get more Missing template exceptions, even if that would actually be a real issue in your code. – Matouš Borák Jun 07 '16 at 09:05