DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Use One Function For Get And Put Actions
This template enables you to use only one function to display a template and process it with the same one.
def new if request.get? # no post data, so create a new instance and render the template @post = Post.new else # post-part, form was filled out and we can save the post @post = Post.new(params[:post]) if @post.save flash[:notice] = 'Post was successfully created.' redirect_to :action => 'index' else render :action => 'new' end end end