【发布时间】:2011-02-03 18:57:08
【问题描述】:
在 rails 3 中,我在照片控制器中的销毁操作有以下代码
def destroy
@photo = Photo.find(params[:id])
if @photo.destroy
flash[:notice] = t('photo.deleted')
respond_to do |format|
if request.xhr?
format.js
else
format.html {redirect_to photos_path}
end
end
else
flash[:alert] = t('.photo.error_deleting')
if request.xhr?
redirect_to(photos_url)
else
redirect_to(photo_path @photo)
end
end
end
如果从标准链接调用,目标本质上是重定向到索引页面,如果从远程链接调用,则呈现destroy.js。 这可行,但我想知道在 rails 3 中是否有更清洁的方法。可能使用 respond_with 运算符?
谢谢
【问题讨论】:
标签: ruby-on-rails ajax ruby-on-rails-3 redirect render