0
votes

When a user successfully updates a record using the edit form, I'd like it to re-render the form with the notice (like the wordpress dashboard does). Right now, when someone successfully updates a page record, the view isn't updated. Here is the update method in my Admin::Page controller:

def update
  @page = Page.find_by_permalink!(params[:id])
  if @page.published? && @page.published_at == nil
    @page.published_at = Time.now
  elsif [email protected]? && @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

What should I substitute for render action: "edit"?

1

1 Answers

1
votes

Try this:-

def update
  @page = Page.find_by_permalink!(params[:id])
  if @page.published? && @page.published_at == nil
    @page.published_at = Time.now
  elsif [email protected]? && @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

Change edit_page_path(@page) with the path for edit action.