【发布时间】:2025-12-30 01:50:12
【问题描述】:
我们如何在 rails redirect_to 方法中只传递非空参数?
我知道我们可以通过以下方式将参数传递给redirect_to:
redirect_to :action => "action1", :foo => bar
当变量 'bar' 可能为 nil 或为空时,是否有任何优雅/更好的方法来传递它?
现在,我在做redirect_to 之前检查bar 是否为空白。但我觉得这可以用更优雅的方式来完成。
if bar.blank?
redirect_to :action => "action1"
else
redirect_to :action => "action1", :foo => bar
end
【问题讨论】:
标签: ruby-on-rails