text: Q:
  
  Stay on the same page after edit
  
  I'm trying to follow the RailsTutorial guide, but by doing my own application instead. I have trouble with section 7, with the forms.
  My controller :
    def update
      d = Deck.find(params[:id])
      d.title = params[:deck][:title]
      d.slug = params[:deck][:slug]
      d.category = params[:deck][:category]
  
      if d.save
        redirect_to deck_path(d), notice: "Deck saved successfully"
      else
        render :edit
      end
  
    end
  
  I know it's very, very far from good code, but I will refactor it later (if you have a suggestion I'm all ears, but I use Rails 3, so I guess the strong parameters of Rails 4 are out).
  The problem is when the d.save does not work (due to validation), with the render :edit.
  Right now, when I enter invalid data, it tries to redirect to the show action, and crashes because it does not have any data to display.
  If I add @deck = d above the render, it works, but the url still is the show action.
  If my validation fail, how can I stay on the same URL and display my error messages ? Is the "change URL but render the same page" behavior accepted as valid ?
  Thanks !
  If you're interested in looking at the rest of the code, it's here : https://github.com/cosmo0/TeachMTG/tree/remodel-decks
  
  A:
  
  Actually when it fails your url is not the 'show' it is the 'update' url.
  Your code works.
  When you submit your form, your browser sends a POST request to controller#update.
  When the update fails, you tell your update action to "render :edit". What it does is it renders the :edit action inside the :update route.
  The update route uses the same url as your show action :
  you can check this when running 'rake routes', the only difference is that the method is POST for 'update' vs GET for 'show'
  That's why you think it is the show url in the browser but actually everything works: you are on the update action that renders :edit.
  (Telling your update action to 'render :edit' doesn't mean you are redirected to :edit back from :update)
  Is that clear enough ?
  
  