ActionView :: MissingTemplate: Missing template (attempt to create nonexistent: mobile format)

I have index.js that starts normally from the desktop, but when I try to open with Mobile Safari, the following error appears.

 ActionView::MissingTemplate: Missing template ads/thumbs/index, application/index with {:locale=>[:es, :en], :formats=>[:mobile], :handlers=>[:erb, :builder, :haml]}. Searched in: * "/app/app/views" * "/app/vendor/bundle/ruby/1.9.1/gems/devise-1.5.2/app/views" * "/app/app/views" 

I am not sure why it is looking for :formats=>[:mobile] when there is no such file in the folder.

The same thing happens after you try to log in using your mobile phone. I am trying to make a nonexistent create.mobile.haml file.

PS Is there a way to make the :mobile views the default backup views :html if they are not found? That would do the trick.

0
source share
2 answers

In general, you must respond with specific types of content. In this case, an easy way to overcome this short-term problem is to rename index.js to index.mobile.js .

Rails tries to display views specific to the requested content type, for example, index.html.haml when requesting html or show.json.haml if you are requesting json. In this case, the requested content type is :mobile .

Ultimately, you must develop views that will be sent back when you request different types of content.

0
source

Here is a simple solution.

 class ApplicationController ... def formats=(values) values << :html if values == [:mobile] super(values) end ... end 

It turns out that Rails (3.2.11) already adds: html fallback for requests with the format: js. Here's ActionView::LookupContext#formats=

 # Override formats= to expand ["*/*"] values and automatically # add :html as fallback to :js. def formats=(values) if values values.concat(default_formats) if values.delete "*/*" values << :html if values == [:js] end super(values) end 

So, you can override #formats= yourself, and it may not be more crude and hacked than the existing Rails implementation.

0
source

Source: https://habr.com/ru/post/1414915/


All Articles