Ruby on rails 三元算子ruby
为什么这不起作用:Ruby on rails 三元算子ruby,ruby-on-rails,ruby,Ruby On Rails,Ruby,为什么这不起作用: 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? ? red
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被空格弄糊涂了。如果将方法调用重写为使用括号,则可以:
params[:mobile].nil? ? redirect_to(home_path) : render(nothing: true, status: 200)
或者,只需使用可读性更高的
if
/then
/else
而不是钝角条件运算符,它恰好具有正确的优先级,因此一切都可以正常工作:if params[:mobile].nil?然后重定向到home路径,否则不渲染任何内容:true,status:200 end
或者,只需使用可读性更高的if
/if
/else
而不是钝条件运算符,因为钝条件运算符恰好具有正确的优先级,因此所有内容都可以正常工作:if params[:mobile]。nil?然后重定向到主路径,否则不呈现任何内容:true,状态:200 end