Over a million developers have joined DZone.

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
Topics:

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

{{ parent.tldr }}

{{ parent.urlSource.name }}