title: rails, preview button in form question
body: <p>I am trying to set up a preview button in an edit form based on the <a href="http://railscasts.com/episodes/38-multibutton-form" rel="nofollow">railscast</a> by Ryan Bates. There are two buttons [edit] and [update]. </p>
  
  <p>When the user clicks the preview button, the "update" function in the controller is called. If I simply set the @article variable based on a find of the article table (as per below controller) the preview button resets the values in the form to the saved data and I lose my edits.</p>
  
  <p>Is there a way I can have a preview mode for updates? New works fine, only edit has this issue.</p>
  
  <pre><code>  def update
      @article = Article.find(params[:id])
  
      if params[:preview_button] || !@article.update_attributes(params[:article])
        render :action =&gt; 'edit'
      else
        respond_to do |format|
          format.html { redirect_to(@article, :notice =&gt; 'Article was successfully updated.') }
        end
      end
    end
  </code></pre>
  
  <p>Edit: I tried using the below code instead</p>
  
  <pre><code>if params[:preview_button] || !@article.update_attributes(params[:article])
    @article = Article.new(params[:article])
    render :action =&gt; 'edit'
  else
  </code></pre>
  
  <p>Which preserves the data, however there's a side-effect. Clicking the preview button from [http://localhost:3000/articles/4/edit] redirects to [http://localhost:3000/articles/4] clicking again here goes to the new view [http://localhost:3000/articles]. </p>