Skip to content
jtPublic

About

bounce is a rails method that saves and returns an active record object. Use to refactor controllers.

Resources

Stars

8 stars

Watchers

1 watching

Forks

Latest commit

 

History

21 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bounce

bounce will save and return an active record object. This results in a nice refactor of update and create actions in your controllers when used withrespond_with.

Refactor this:

  def create
    article = Article.new(params[:article])
    if article.save
      redirect_to article
    else
      render :new
    end
  end

  def update
    article = Article.find(params[:id])
    if article.update_attributes(params[:article])
      redirect_to article
    else
      render :edit
    end
  end

Into this:

  respond_to :html

  def create
    article = Article.new(params[:article])
    respond_with article.bounce
  end

  def update
    article = Article.find(params[:id])
    respond_with article.bounce(params[:article])
  end

If you have more than one controller, extract the respond_to :html into the application controller.

If you use decent_exposure you can do this:

  expose(:article)

  def create
    respond_with article.bounce
  end
  alias update create

Install

Add to your Gemfile in Rails:

gem 'bounce'

About

bounce is a rails method that saves and returns an active record object. Use to refactor controllers.

Resources

Stars

8 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages