Forum: Ruby on Rails Missing template pages/layout only occasionally

Posted by Rick Cockerham (pixie)
on 2012-11-26 19:52
I have my app email me errors when they occur.  I get this about 2-3
times a week with thousands of hits a day to the site.  pages/show is a
.html.erb file that renders the partial
_strategicrelationshipacademy.html.erb essentially.  Or whatever partial
it calls for.  I get this on many different 'pages'.  Obviously the
partial exists if it renders it fine most of the time.  What could cause
this?

Message = Missing template pages/layout with {:formats=>["text/*"],
:locale=>[:en, :en], :handlers=>[:rhtml, :rxml, :builder, :erb, :rjs]}
in view paths "/var/www/procyon-live/app/views",
"/var/www/procyon-live/vendor/plugins/wicked_pdf/app/views",
"/var/www/procyon-live/vendor/plugins/file_column/app/views",
"/var/www/procyon-live/vendor/plugins/acts_as_tree/app/views",
"/var/www/procyon-live/vendor/plugins/acts_as_list/app/views"

Request = {"controller"=>"pages",
"page"=>"strategicrelationshipacademy", "action"=>"show"}

/usr/lib/ruby/gems/1.8/gems/actionpack-3.0.9.rc5/lib/action_view/paths.rb:15:in
`find'
/usr/lib/ruby/gems/1.8/gems/actionpack-3.0.9.rc5/lib/action_view/lookup_context.rb:81:in
`find_template'
...
/usr/lib/ruby/gems/1.8/gems/actionpack-3.0.9.rc5/lib/action_controller/metal/instrumentation.rb:39:in
`render_without_wicked_pdf'
/var/www/procyon-live/vendor/plugins/wicked_pdf/lib/pdf_helper.rb:19:in
`render'
/var/www/procyon-live/app/controllers/pages_controller.rb:154:in `show'
...

Rails 3.0.9.rc5
Ruby 1.8.7

Obviously I didn't want to include the entire backtrace.  Let me know if
it would help.

Thanks,
Rick
Posted by Jim ruther Nill (jimboker)
on 2012-11-27 00:43
(Received via mailing list)
Sent from my iPhone

On 27/11/2012, at 2:52 AM, Rick Cockerham <lists@ruby-forum.com> wrote:

> I have my app email me errors when they occur.  I get this about 2-3
> times a week with thousands of hits a day to the site.  pages/show is a
> .html.erb file that renders the partial
> _strategicrelationshipacademy.html.erb essentially.  Or whatever partial
> it calls for.  I get this on many different 'pages'.  Obviously the
> partial exists if it renders it fine most of the time.  What could cause
> this?
>
> Message = Missing template pages/layout with {:formats=>["text/*"],
> :locale=>[:en, :en], :handlers=>[:rhtml, :rxml, :builder, :erb, :rjs]}

I think it's looking for _partial.text.erb google for browsers that send 
you the text/* format.
Posted by Rick Cockerham (pixie)
on 2012-11-27 00:54
Excellent suggestion.  From the page view I see this agent:

Mozilla/5.0 (compatible; oBot/2.3.1; +http://filterdb.iss.net/crawler/)

So, how do I setup my app to only accept html requests for those routes? 
Or, just not fail when it wants text?

Thanks
Posted by Jim ruther Nill (jimboker)
on 2012-11-27 01:02
(Received via mailing list)
On Tue, Nov 27, 2012 at 7:54 AM, Rick Cockerham 
<lists@ruby-forum.com>wrote:

> Excellent suggestion.  From the page view I see this agent:
>
> Mozilla/5.0 (compatible; oBot/2.3.1; +http://filterdb.iss.net/crawler/)
>
> So, how do I setup my app to only accept html requests for those routes?
> Or, just not fail when it wants text?
>

try passing a formats option to render.

render partial: 'foo', formats: [:html]


> To unsubscribe from this group, send email to
> rubyonrails-talk+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>


--
Posted by Rick Cockerham (pixie)
on 2013-04-25 20:47
I finally figured this out.  I have an action that only renders html, 
but googlebot for instance asks for text format.  So, it tries to find 
action.text.erb which doesn't exist.

I added this to my controller and everything works now.

before_filter :force_html_requests, :only => :show

def force_html_requests
  request.format = :html
end
Posted by Rick (Guest)
on 2013-04-26 10:50
(Received via mailing list)
I finally figured this out.  I have an action that only renders html, 
but
googlebot for instance wants text.  So, I added this to the controller 
and
everything works!

 before_filter :force_html_requests, :only => :show

  def force_html_requests
      request.format = :html
  end

Rick
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.