当用户使用编辑表单成功更新记录时,我希望它通过通知重新呈现表单(就像wordpress仪表板那样)。现在,当有人成功更新页面记录时,视图不会更新。这是我的Admin :: Page控制器中的更新方法:
def update
@page = Page.find_by_permalink!(params[:id])
if @page.published? && @page.published_at == nil
@page.published_at = Time.now
elsif !@page.published? && @page.published_at != nil
@page.published_at = nil
end
if @page.update_attributes(page_params)
render action: "edit", notice: 'Page was successfully updated.'
else
render action: "edit"
end
end
我应该用什么代替渲染动作:“编辑”?
答案 0 :(得分:1)
试试这个: -
def update
@page = Page.find_by_permalink!(params[:id])
if @page.published? && @page.published_at == nil
@page.published_at = Time.now
elsif !@page.published? && @page.published_at != nil
@page.published_at = nil
end
if @page.update_attributes(page_params)
redirect_to({ action: 'edit',id: @page }, notice: 'Page was successfully updated.') #works on rails >=3.1 OR try the commented line below.
#redirect_to edit_page_path(@page), notice: 'Page was successfully updated.'
else
render action: "edit"
end
end
使用修改操作路径更改 edit_page_path(@page)。