为什么这不起作用:
params[:mobile].nil? ? redirect_to home_path : render nothing: true, status: 200
适用于所有其他三元情况,例如:
if_this_is_a_true_value ? then_the_result_is_this : else_it_is_this
有人能看到我在这里没有看到的东西吗?
最佳答案
Ruby 对空格感到困惑。如果您重写方法调用以使用括号,它将起作用:
params[:mobile].nil? ? redirect_to(home_path) : render(nothing: true, status: 200)
关于ruby-on-rails - 三元运算符 ruby,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25022042/