我在一个控制器中有以下代码:
def create
photo.user = current_user if current_user
flash[:notice] = "The photos was saved" if photo.save
respond_with photo, :location => photo_path(photo)
end
这段代码在一个例外情况下可用。如果我使用某种 AJAX 访问此操作,然后访问另一页,将显示闪存通知。如何仅在响应 :html 时显示闪存通知?我认为可能可以通过将 :notice => "my flash" 传递给 respond_with
来实现,但没有成功。
respond_to
转向更简洁的respond_with
。 - Kyle Decotrespond_with
的问题。 - Lester Peabody