我维护了一个 Ruby-on-Rails 网站(实际上运行的是 JRuby 1.5.5,Rails 版本 2.3.10)并且看到了一些相当奇怪的东西。当搜索引擎机器人访问时,某个控制器操作导致日志中出现异常:
ActionView::TemplateError (can't convert nil into String) on line #14 of app/vie
ws/scenarios/show_send_message.rhtml:
11: <% if ! is_logged_in? %>
12: <p>Your email (optional, used to contact you if necessary):<br /><%= tex
t_field_tag 'user_email', @user_email || '', :size => 50 %>
13: <% if ! is_human? %>
14: <%= show_simple_captcha %>
15: <% end %>
16: <% end %>
17: <p><%= submit_tag 'Send' %>
...但是,当我以人的身份查看该页面时,它可以正常工作。"show_simple_captcha" 是来自插件的方法,它不能返回 nil。
有谁知道为什么 RoR 对机器人的响应与对真实浏览器的响应不同?我不是在寻找问题的答案,因为我是进行调试的一种方式,但我很乐意接受前者。