Skip to content
/ bounce Public

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

License

Notifications You must be signed in to change notification settings

jt/bounce

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages