Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 三元算子ruby_Ruby On Rails_Ruby - Fatal编程技术网

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