Fixes GH-1892 by properly updating the form action when the title is changed during save-and-continue #1944

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
3 participants
Contributor

tsemana commented Sep 14, 2012

Passes the admin_pages_path url using the items current title back to the view using a hidden field tag. The save-and-continue javascript then updates the form action with the new url.
Includes request spec for the first save-and-continue and regression test for the bug described in GH-1892.

core/app/views/refinery/_message.html.erb
+ <%= value %>
+ <%= link_to t(".close#{'_this_message' if key.to_s == "message"}"), "",
+ :id => "flash_close" %>
+ </div>
@parndt

parndt Sep 14, 2012

Owner

indentation doesn't match opening <div

core/app/views/refinery/_message.html.erb
+ <div id='flash' class="flash flash_<%= key %>" style='visibility: hidden;' >
+ <%= value %>
+ <%= link_to t(".close#{'_this_message' if key.to_s == "message"}"), "",
+ :id => "flash_close" %>
@parndt

parndt Sep 14, 2012

Owner

can you line up the :id with the t( as before?

core/lib/refinery/crud.rb
- render :partial => '/refinery/message'
+ render :partial => '/refinery/message',
+ #pass the new update url in case the title was updated
+ :locals => {:new_url => refinery.admin_page_path(@#{singular_name}.uncached_nested_url) }
@parndt

parndt Sep 14, 2012

Owner

this shouldn't go in crud because it only applies to admin/pages_controller

@tsemana

tsemana Sep 14, 2012

Contributor

Thanks, should I carry over the whole update method over to admin/pages_controller? or is there a way to narrow it down to when it's an xhr request?

@parndt

parndt Sep 14, 2012

Owner

You'll have to override the entire method unfortunately.

@parndt

parndt Sep 14, 2012

Owner
$ rake app:refinery:uncrudify controller=refinery/admin/pages action=update
def update
  if @page.update_attributes(params[:page])
    flash.notice = t(
      'refinery.crudify.updated',
      :what => "'#{@page.title}'"
    )

    unless from_dialog?
      unless params[:continue_editing] =~ /true|on|1/
        redirect_back_or_default(refinery.admin_pages_path)
      else
        unless request.xhr?
          redirect_to :back
        else
          render :partial => '/refinery/message', :locals => {
            :new_url => refinery.admin_page_path(@page.uncached_nested_url) 
          }
        end
      end
    else
      self.index
      @dialog_successful = true
      render :index
    end
  else
    unless request.xhr?
      render :action => 'edit'
    else
      render :partial => '/refinery/admin/error_messages', :locals => {
               :object => @page,
               :include_object_name => true
             }
    end
  end
end
Owner

ugisozols commented Sep 15, 2012

Looking good.

@tsemana will you tackle preview bug we were talking about in irc?

Contributor

tsemana commented Sep 15, 2012

Thanks, yes I will. It's weird in that the regression spec I wrote works passes even though it fails when done manually... Either way I'll give it a crack

Owner

parndt commented Sep 18, 2012

Merged to 6d5c910 thanks!

@parndt parndt closed this Sep 18, 2012

ugisozols added a commit that referenced this pull request Sep 19, 2012

ugisozols added a commit that referenced this pull request Sep 19, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment