Skip to content

Instantly share code, notes, and snippets.

@spohlenz
Created November 16, 2008 22:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spohlenz/25583 to your computer and use it in GitHub Desktop.
Save spohlenz/25583 to your computer and use it in GitHub Desktop.
New controller pattern
class RecipesController < ApplicationController
...
def new
@recipe = flash[:recipe] || Recipe.new
end
def create
@recipe = Recipe.new(params[:recipe])
if @recipe.save
flash[:notice] = 'Recipe was successfully created.'
redirect_to recipes_path
else
flash[:recipe] = @recipe
redirect_to new_recipe_path
end
end
...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment