Over a million developers have joined DZone.

Use One Function For Get And Put Actions

DZone's Guide to

Use One Function For Get And Put Actions

Free Resource
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'
      render :action => 'new'

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}