【发布时间】:2012-12-13 20:17:04
【问题描述】:
在我的 Rails 应用程序中,我正在寻找一种保存帖子的方法,并提出“已保存”的通知。无需重定向到任何地方。
我可以在控制器中执行此操作还是必须使用 Ajax?如果我必须使用 Ajax,有没有简单的方法来实现它?
以下是我的控制器中的创建和更新操作:
def create
@document = current_user.documents.build(params[:document])
if @document.save
redirect_to @document.edit, notice: 'Saved'
else
render action: "new"
end
end
def update
@document = current_user.documents.find_by_url_id(params[:id])
if @document.update_attributes(params[:document])
redirect_to @document, notice: 'Saved'
else
render action: "edit"
end
end
【问题讨论】:
标签: javascript ruby-on-rails ruby ajax