我希望我的Controller中的两个动作在ajax调用的情况下返回到查看文件showcomment.js.erb,并且它在showcooment.js.erb中运行正常。但我想将删除操作的视图也返回到showcomment.js.erb。怎么做到呢?
def showcomment
@article = Article.find(params[:id])
@comments = @article.comments
respond_to do |format|
format.js
end
end
def deletecomment
@comment = comment.find(params[:id])
@comment.destroy
respond_to do |format|
format.js
end
end
答案 0 :(得分:1)
试试这个:
def deletecomment
@comment = comment.find(params[:id])
@comment.destroy
respond_to do |format|
format.js{ render :action => 'showcomment' }
end
end