Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8849497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:40:08+00:00 2026-06-14T12:40:08+00:00

Following the helpful tutorial in Railscasts #38 http://railscasts.com/episodes/38-multibutton-form I set up a Preview button

  • 0

Following the helpful tutorial in Railscasts #38 http://railscasts.com/episodes/38-multibutton-form I set up a “Preview” button for my “New”/”Create” controller actions.

But when I use the same method for “Edit”/”Update” there seems to be a problem.

I can’t seem to get my form to persist.

Here’s what my controller looks like:

def update
    stylesheets << 'feature'

    @feature = Feature.find(params[:id])

    case params[:submit]
        when "Preview" 
            render :action => "edit"
        return

        when "Update" 
            respond_to do |format|
                if @feature.update_attributes(params[:feature])
                    flash[:notice] = 'Feature was successfully updated.'
                    format.html { redirect_to(features_path) }
                    format.xml  { head :ok }
                else
                    format.html { render :action => "edit" }
                    format.xml  { render :xml => @feature.errors, :status => :unprocessable_entity }
                end
            end
        return
    end

end

When I hit the preview button, I am returned to an editing screen as expected, but my edits don’t persist. Any tips? Curious, as this works fine for previewing New objects.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:40:09+00:00Added an answer on June 14, 2026 at 12:40 pm

    What’s happening here is that you’re not actually applying the changes the user made to the in-memory model before rendering your view, so the changes get lost.

    Try changing your ‘Preview’ case like this:

    when "Preview"
      @feature.attributes = params[:feature]
      render :action => "edit"
      return
    

    One thing I would say is that I’d also consider splitting that method up a bit to make it easier to read and test. Something like this:

    before_filter :set_stylesheets
    
    def set_stylesheets
      stylesheets << 'feature'
    end
    
    def update
      @feature = Feature.find(params[:id])
      preview if params[:submit] == 'Preview'
      apply_update if params[:submit] == 'Update'
    end
    
    def preview
      @feature.attributes = params[:feature]
      render :action => "edit"
      return
    end
    
    def apply_update
      # Rest of update action here.
    end
    

    This helps you keep your tests simple and focussed on one method at a time, and should make the code easier to maintain.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have followed this tutorial to create the first azure application http://msdn.microsoft.com/en-us/WAZPlatformTrainingCourse_IntroToWindowsAzureLabVS2010 Because after
Ok I'm following this tutorial for a basic PHP webservice server/client setup: http://www.java-samples.com/showtutorial.php?tutorialid=1186 Now
Following chunk html code works as expected: <iframe src=http://www.amazon.com/></iframe> But when trying embed inner
I'm Following the wonderful Michael Hartl's tutorial which can be found here: http://ruby.railstutorial.org/ I'm
I have to following code: http://www.nomorepasting.com/getpaste.php?pasteid=22987 If PHPSESSID is not already in the table
I am having an issue with parsing the following website: http://www.x-rates.com/d/USD/table.html I am very,
I have got the following code in a button on a form, but I
Following leads in this thread and others, I've set up a code block where
Following is the Play 2 app, https://github.com/playframework/Play20/tree/master/samples/java/forms Which portrays Dynamic form binding where form
I'm pretty new to Java and am following the Eclipse Total Beginner's Tutorials .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.