简体   繁体   English

对controller.request.format.html的奇怪响应? 在Rails中

[英]Weird response for controller.request.format.html? in Rails

In my main controller, I have this: 在我的主控制器中,我有这个:

class MainController < ApplicationController  

  before_filter do |controller|
    logger.info "controller.request.format.html? = #{controller.request.format.html?}"
    logger.info "controller.request.format.fbml? = #{controller.request.format.fbml?}"
    controller.send :login_required if controller.request.format.html?
    controller.send :facebook_auth_required if controller.request.format.fbml?
  end

As expected, I get "true" for the ...fbml? 不出所料,我对... fbml表示“真实”? line if a request comes from Facebook (my facebooker gem automatically sets the format). 如果有来自Facebook的请求,则此行(我的facebooker gem自动设置格式)。 However, I get "5" for the ...html? 但是,... html的值是“ 5”吗? line if the request comes from Facebook. 如果请求来自Facebook,则此行。 Why would a method with a ? 为什么要用一个方法? ever return a "5"? 曾经返回“ 5”吗? Isn't that against Rails conventions? 这不是违反Rails约定吗? Also, I think "5" is considered true so this might mess up my filters. 另外,我认为“ 5”是正确的,因此这可能会弄乱我的过滤器。 Still looking into that... 仍在调查...

Any ideas? 有任何想法吗?

The only things that evaluate to false in Ruby are false and nil . 在Ruby中唯一评估为false的是falsenil Here's a great lightning talk from last year's RubyConf that pretty much explains it all in less than seven minutes: The Nature of Truth 这是去年RubyConf上的一次精彩的闪电演讲,几乎在不到七分钟的时间内就解释了这一切: 真相的本质

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM